mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
fix deprecations: systematic use of fqcn in getParent functions
This commit is contained in:
parent
3459755d7a
commit
769c9e4e59
@ -22,28 +22,30 @@ namespace Chill\PersonBundle\Form\Type;
|
|||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Chill\MainBundle\Entity\Center;
|
|
||||||
use Chill\PersonBundle\Entity\PersonRepository;
|
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
|
||||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||||
use Symfony\Component\Security\Core\Role\Role;
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\GroupCenter;
|
use Chill\MainBundle\Entity\GroupCenter;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
||||||
|
use Chill\MainBundle\Entity\Center;
|
||||||
|
use Chill\PersonBundle\Entity\PersonRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This type allow to pick a person.
|
* This type allow to pick a person.
|
||||||
*
|
*
|
||||||
* The form is embedded in a select2 input.
|
* The form is embedded in a select2 input.
|
||||||
*
|
*
|
||||||
* The people may be filtered :
|
* The people may be filtered :
|
||||||
*
|
*
|
||||||
* - with the `centers` option, only the people associated with the given center(s)
|
* - with the `centers` option, only the people associated with the given center(s)
|
||||||
* are seen. May be an instance of `Chill\MainBundle\Entity\Center`, or an array of
|
* are seen. May be an instance of `Chill\MainBundle\Entity\Center`, or an array of
|
||||||
* `Chill\MainBundle\Entity\Center`. By default, all the reachable centers as selected.
|
* `Chill\MainBundle\Entity\Center`. By default, all the reachable centers as selected.
|
||||||
* - with the `role` option, only the people belonging to the reachable center for the
|
* - with the `role` option, only the people belonging to the reachable center for the
|
||||||
* given role are displayed.
|
* given role are displayed.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||||
*/
|
*/
|
||||||
@ -53,19 +55,19 @@ class PickPersonType extends AbstractType
|
|||||||
* @var PersonRepository
|
* @var PersonRepository
|
||||||
*/
|
*/
|
||||||
protected $personRepository;
|
protected $personRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var \Chill\MainBundle\Entity\User
|
* @var \Chill\MainBundle\Entity\User
|
||||||
*/
|
*/
|
||||||
protected $user;
|
protected $user;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var AuthorizationHelper
|
* @var AuthorizationHelper
|
||||||
*/
|
*/
|
||||||
protected $authorizationHelper;
|
protected $authorizationHelper;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
PersonRepository $personRepository,
|
PersonRepository $personRepository,
|
||||||
TokenStorageInterface $tokenStorage,
|
TokenStorageInterface $tokenStorage,
|
||||||
@ -76,21 +78,21 @@ class PickPersonType extends AbstractType
|
|||||||
$this->user = $tokenStorage->getToken()->getUser();
|
$this->user = $tokenStorage->getToken()->getUser();
|
||||||
$this->authorizationHelper = $authorizationHelper;
|
$this->authorizationHelper = $authorizationHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$qb = $options['query_builder'];
|
$qb = $options['query_builder'];
|
||||||
|
|
||||||
if ($options['role'] === NULL) {
|
if ($options['role'] === NULL) {
|
||||||
$centers = array_map(function (GroupCenter $g) {
|
$centers = array_map(function (GroupCenter $g) {
|
||||||
|
|
||||||
return $g->getCenter();
|
return $g->getCenter();
|
||||||
}, $this->user->getGroupCenters()->toArray());
|
}, $this->user->getGroupCenters()->toArray());
|
||||||
} else {
|
} else {
|
||||||
$centers = $this->authorizationHelper
|
$centers = $this->authorizationHelper
|
||||||
->getReachableCenters($this->user, $options['role']);
|
->getReachableCenters($this->user, $options['role']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($options['centers'] === NULL) {
|
if ($options['centers'] === NULL) {
|
||||||
// we select all selected centers
|
// we select all selected centers
|
||||||
$selectedCenters = $centers;
|
$selectedCenters = $centers;
|
||||||
@ -98,10 +100,10 @@ class PickPersonType extends AbstractType
|
|||||||
$selectedCenters = array();
|
$selectedCenters = array();
|
||||||
$options['centers'] = is_array($options['centers']) ?
|
$options['centers'] = is_array($options['centers']) ?
|
||||||
$options['centers'] : array($options['centers']);
|
$options['centers'] : array($options['centers']);
|
||||||
|
|
||||||
foreach ($options['centers'] as $c) {
|
foreach ($options['centers'] as $c) {
|
||||||
// check that every member of the array is a center
|
// check that every member of the array is a center
|
||||||
if (!$c instanceof Center) {
|
if (!$c instanceof Center) {
|
||||||
throw new \RuntimeException('Every member of the "centers" '
|
throw new \RuntimeException('Every member of the "centers" '
|
||||||
. 'option must be an instance of '.Center::class);
|
. 'option must be an instance of '.Center::class);
|
||||||
}
|
}
|
||||||
@ -113,8 +115,8 @@ class PickPersonType extends AbstractType
|
|||||||
$selectedCenters[] = $c;
|
$selectedCenters[] = $c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$qb
|
$qb
|
||||||
->orderBy('p.firstName', 'ASC')
|
->orderBy('p.firstName', 'ASC')
|
||||||
->orderBy('p.lastName', 'ASC')
|
->orderBy('p.lastName', 'ASC')
|
||||||
@ -122,11 +124,11 @@ class PickPersonType extends AbstractType
|
|||||||
->setParameter('centers', $selectedCenters)
|
->setParameter('centers', $selectedCenters)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureOptions(OptionsResolver $resolver)
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
{
|
{
|
||||||
parent::configureOptions($resolver);
|
parent::configureOptions($resolver);
|
||||||
|
|
||||||
// add the possibles options for this type
|
// add the possibles options for this type
|
||||||
$resolver->setDefined('centers')
|
$resolver->setDefined('centers')
|
||||||
->addAllowedTypes('centers', array('array', Center::class, 'null'))
|
->addAllowedTypes('centers', array('array', Center::class, 'null'))
|
||||||
@ -135,7 +137,7 @@ class PickPersonType extends AbstractType
|
|||||||
->addAllowedTypes('role', array(Role::class, 'null'))
|
->addAllowedTypes('role', array(Role::class, 'null'))
|
||||||
->setDefault('role', null)
|
->setDefault('role', null)
|
||||||
;
|
;
|
||||||
|
|
||||||
// add the default options
|
// add the default options
|
||||||
$resolver->setDefaults(array(
|
$resolver->setDefaults(array(
|
||||||
'class' => Person::class,
|
'class' => Person::class,
|
||||||
@ -152,10 +154,10 @@ class PickPersonType extends AbstractType
|
|||||||
'query_builder' => $this->personRepository->createQueryBuilder('p')
|
'query_builder' => $this->personRepository->createQueryBuilder('p')
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getParent()
|
public function getParent()
|
||||||
{
|
{
|
||||||
return \Symfony\Bridge\Doctrine\Form\Type\EntityType::class;
|
return EntityType::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user