[closing motive] add an hierarchy + admin section for closing motives

This commit is contained in:
2020-03-12 12:19:15 +01:00
parent ceb3b5e955
commit e59f58f461
26 changed files with 712 additions and 41 deletions

View File

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