diff --git a/src/Bundle/ChillPersonBundle/Entity/Person.php b/src/Bundle/ChillPersonBundle/Entity/Person.php index b1048ea60..7aacf6ba8 100644 --- a/src/Bundle/ChillPersonBundle/Entity/Person.php +++ b/src/Bundle/ChillPersonBundle/Entity/Person.php @@ -1182,9 +1182,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @param string $phonenumber * @return Person */ - public function setPhonenumber($phonenumber = '') + public function setPhonenumber(?string $phonenumber = '') { - $this->phonenumber = $phonenumber; + $this->phonenumber = (string) $phonenumber; return $this; } @@ -1205,9 +1205,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI * @param string $mobilenumber * @return Person */ - public function setMobilenumber($mobilenumber = '') + public function setMobilenumber(?string $mobilenumber = '') { - $this->mobilenumber = $mobilenumber; + $this->mobilenumber = (string) $mobilenumber; return $this; } diff --git a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php index 8fa95fe4f..3fa8f5cda 100644 --- a/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php +++ b/src/Bundle/ChillPersonBundle/Form/CreationPersonType.php @@ -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, [ diff --git a/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/PersonHasCenterValidator.php b/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/PersonHasCenterValidator.php index 1738e6ddc..825084448 100644 --- a/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/PersonHasCenterValidator.php +++ b/src/Bundle/ChillPersonBundle/Validator/Constraints/Person/PersonHasCenterValidator.php @@ -2,6 +2,7 @@ namespace Chill\PersonBundle\Validator\Constraints\Person; +use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher; use Chill\PersonBundle\Entity\Person; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Validator\Constraint; @@ -10,10 +11,12 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException; class PersonHasCenterValidator extends \Symfony\Component\Validator\ConstraintValidator { private bool $centerRequired; + private CenterResolverDispatcher $centerResolverDispatcher; - public function __construct(ParameterBagInterface $parameterBag) + public function __construct(ParameterBagInterface $parameterBag, CenterResolverDispatcher $centerResolverDispatcher) { $this->centerRequired = $parameterBag->get('chill_person')['validation']['center_required']; + $this->centerResolverDispatcher = $centerResolverDispatcher; } /** @@ -29,7 +32,7 @@ class PersonHasCenterValidator extends \Symfony\Component\Validator\ConstraintVa return; } - if (NULL === $person->getCenter()) { + if (NULL === $this->centerResolverDispatcher->resolveCenter($person)) { $this ->context ->buildViolation($constraint->message)