mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 05:44:58 +00:00
[closing motive] add an hierarchy + admin section for closing motives
This commit is contained in:
@@ -9,13 +9,15 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Chill\PersonBundle\Repository\ClosingMotiveRepository;
|
||||
|
||||
/**
|
||||
* A type to add a closing motive
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class ClosingMotiveType extends AbstractType
|
||||
class ClosingMotivePickerType extends AbstractType
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -24,9 +26,26 @@ class ClosingMotiveType extends AbstractType
|
||||
*/
|
||||
protected $translatableStringHelper;
|
||||
|
||||
public function __construct(TranslatableStringHelper $translatableStringHelper)
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ChillEntityRenderExtension
|
||||
*/
|
||||
protected $entityRenderExtension;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var ClosingMotiveRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
ChillEntityRenderExtension $chillEntityRenderExtension,
|
||||
ClosingMotiveRepository $closingMotiveRepository
|
||||
) {
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->entityRenderExtension = $chillEntityRenderExtension;
|
||||
$this->repository = $closingMotiveRepository;
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
@@ -46,11 +65,17 @@ class ClosingMotiveType extends AbstractType
|
||||
'empty_data' => null,
|
||||
'placeholder' => 'Choose a motive',
|
||||
'choice_label' => function(ClosingMotive $cm) {
|
||||
return $this->translatableStringHelper
|
||||
->localize($cm->getName());
|
||||
}
|
||||
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']);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user