mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 05:44:58 +00:00
This commit is contained in:
@@ -14,30 +14,36 @@ use Symfony\Component\OptionsResolver\Options;
|
||||
use Chill\PersonBundle\Repository\ClosingMotiveRepository;
|
||||
|
||||
/**
|
||||
* Class ClosingMotivePickerType
|
||||
* A type to add a closing motive
|
||||
*
|
||||
* @package Chill\PersonBundle\Form\Type
|
||||
*/
|
||||
class ClosingMotivePickerType extends AbstractType
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ChillEntityRenderExtension
|
||||
*/
|
||||
protected $entityRenderExtension;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ClosingMotiveRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
|
||||
/**
|
||||
* ClosingMotivePickerType constructor.
|
||||
*
|
||||
* @param TranslatableStringHelper $translatableStringHelper
|
||||
* @param ChillEntityRenderExtension $chillEntityRenderExtension
|
||||
* @param ClosingMotiveRepository $closingMotiveRepository
|
||||
*/
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
ChillEntityRenderExtension $chillEntityRenderExtension,
|
||||
@@ -47,35 +53,46 @@ class ClosingMotivePickerType extends AbstractType
|
||||
$this->entityRenderExtension = $chillEntityRenderExtension;
|
||||
$this->repository = $closingMotiveRepository;
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'closing_motive';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return EntityType::class;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param OptionsResolver $resolver
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'class' => ClosingMotive::class,
|
||||
'empty_data' => null,
|
||||
'placeholder' => 'Choose a motive',
|
||||
'choice_label' => function(ClosingMotive $cm) {
|
||||
return $this->entityRenderExtension->renderString($cm);
|
||||
},
|
||||
'only_leaf' => true
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
$resolver->setDefaults([
|
||||
'class' => ClosingMotive::class,
|
||||
'empty_data' => null,
|
||||
'placeholder' => 'Choose a motive',
|
||||
'choice_label' => function(ClosingMotive $cm) {
|
||||
return $this->entityRenderExtension->renderString($cm);
|
||||
},
|
||||
'only_leaf' => true
|
||||
]);
|
||||
|
||||
$resolver
|
||||
->setAllowedTypes('only_leaf', 'bool')
|
||||
->setNormalizer('choices', function (Options $options) {
|
||||
return $this->repository->getActiveClosingMotive($options['only_leaf']);
|
||||
});
|
||||
return $this->repository
|
||||
->getActiveClosingMotive($options['only_leaf']);
|
||||
})
|
||||
;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user