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

@@ -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)