2021-02-03 18:50:34 +01:00
parent 03cafbf4c6
commit c76e401021
6 changed files with 152 additions and 78 deletions

View File

@@ -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']);
})
;
}
}