take parameter form_show_center into account: not to ask center on person creation

This commit is contained in:
2021-11-15 13:06:47 +01:00
parent b217fb3c39
commit 77add46a70
3 changed files with 24 additions and 13 deletions

View File

@@ -25,6 +25,7 @@ use Chill\MainBundle\Form\Event\CustomizeFormEvent;
use Chill\MainBundle\Repository\CenterRepository;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
@@ -54,14 +55,18 @@ final class CreationPersonType extends AbstractType
private EventDispatcherInterface $dispatcher;
private bool $askCenters;
public function __construct(
CenterRepository $centerRepository,
ConfigPersonAltNamesHelper $configPersonAltNamesHelper,
EventDispatcherInterface $dispatcher
EventDispatcherInterface $dispatcher,
ParameterBagInterface $parameterBag
) {
$this->centerTransformer = $centerRepository;
$this->configPersonAltNamesHelper = $configPersonAltNamesHelper;
$this->dispatcher = $dispatcher;
$this->askCenters = $parameterBag->get('chill_main')['acl']['form_show_centers'];
}
/**
@@ -78,12 +83,15 @@ final class CreationPersonType extends AbstractType
])
->add('gender', GenderType::class, array(
'required' => true, 'placeholder' => null
))
->add('center', PickCenterType::class, [
'required' => false,
'role' => PersonVoter::CREATE,
])
;
));
if ($this->askCenters) {
$builder
->add('center', PickCenterType::class, [
'required' => false,
'role' => PersonVoter::CREATE,
]);
}
if ($this->configPersonAltNamesHelper->hasAltNames()) {
$builder->add('altNames', PersonAltNameType::class, [