mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
take parameter form_show_center
into account: not to ask center on person creation
This commit is contained in:
parent
b217fb3c39
commit
77add46a70
@ -1182,9 +1182,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
* @param string $phonenumber
|
* @param string $phonenumber
|
||||||
* @return Person
|
* @return Person
|
||||||
*/
|
*/
|
||||||
public function setPhonenumber($phonenumber = '')
|
public function setPhonenumber(?string $phonenumber = '')
|
||||||
{
|
{
|
||||||
$this->phonenumber = $phonenumber;
|
$this->phonenumber = (string) $phonenumber;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -1205,9 +1205,9 @@ class Person implements HasCenterInterface, TrackCreationInterface, TrackUpdateI
|
|||||||
* @param string $mobilenumber
|
* @param string $mobilenumber
|
||||||
* @return Person
|
* @return Person
|
||||||
*/
|
*/
|
||||||
public function setMobilenumber($mobilenumber = '')
|
public function setMobilenumber(?string $mobilenumber = '')
|
||||||
{
|
{
|
||||||
$this->mobilenumber = $mobilenumber;
|
$this->mobilenumber = (string) $mobilenumber;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ use Chill\MainBundle\Form\Event\CustomizeFormEvent;
|
|||||||
use Chill\MainBundle\Repository\CenterRepository;
|
use Chill\MainBundle\Repository\CenterRepository;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
@ -54,14 +55,18 @@ final class CreationPersonType extends AbstractType
|
|||||||
|
|
||||||
private EventDispatcherInterface $dispatcher;
|
private EventDispatcherInterface $dispatcher;
|
||||||
|
|
||||||
|
private bool $askCenters;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
CenterRepository $centerRepository,
|
CenterRepository $centerRepository,
|
||||||
ConfigPersonAltNamesHelper $configPersonAltNamesHelper,
|
ConfigPersonAltNamesHelper $configPersonAltNamesHelper,
|
||||||
EventDispatcherInterface $dispatcher
|
EventDispatcherInterface $dispatcher,
|
||||||
|
ParameterBagInterface $parameterBag
|
||||||
) {
|
) {
|
||||||
$this->centerTransformer = $centerRepository;
|
$this->centerTransformer = $centerRepository;
|
||||||
$this->configPersonAltNamesHelper = $configPersonAltNamesHelper;
|
$this->configPersonAltNamesHelper = $configPersonAltNamesHelper;
|
||||||
$this->dispatcher = $dispatcher;
|
$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(
|
->add('gender', GenderType::class, array(
|
||||||
'required' => true, 'placeholder' => null
|
'required' => true, 'placeholder' => null
|
||||||
))
|
));
|
||||||
->add('center', PickCenterType::class, [
|
|
||||||
'required' => false,
|
if ($this->askCenters) {
|
||||||
'role' => PersonVoter::CREATE,
|
$builder
|
||||||
])
|
->add('center', PickCenterType::class, [
|
||||||
;
|
'required' => false,
|
||||||
|
'role' => PersonVoter::CREATE,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->configPersonAltNamesHelper->hasAltNames()) {
|
if ($this->configPersonAltNamesHelper->hasAltNames()) {
|
||||||
$builder->add('altNames', PersonAltNameType::class, [
|
$builder->add('altNames', PersonAltNameType::class, [
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Chill\PersonBundle\Validator\Constraints\Person;
|
namespace Chill\PersonBundle\Validator\Constraints\Person;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
use Symfony\Component\Validator\Constraint;
|
use Symfony\Component\Validator\Constraint;
|
||||||
@ -10,10 +11,12 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|||||||
class PersonHasCenterValidator extends \Symfony\Component\Validator\ConstraintValidator
|
class PersonHasCenterValidator extends \Symfony\Component\Validator\ConstraintValidator
|
||||||
{
|
{
|
||||||
private bool $centerRequired;
|
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->centerRequired = $parameterBag->get('chill_person')['validation']['center_required'];
|
||||||
|
$this->centerResolverDispatcher = $centerResolverDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,7 +32,7 @@ class PersonHasCenterValidator extends \Symfony\Component\Validator\ConstraintVa
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL === $person->getCenter()) {
|
if (NULL === $this->centerResolverDispatcher->resolveCenter($person)) {
|
||||||
$this
|
$this
|
||||||
->context
|
->context
|
||||||
->buildViolation($constraint->message)
|
->buildViolation($constraint->message)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user