Commit 769c9e4e authored by Julien Minet's avatar Julien Minet

fix deprecations: systematic use of fqcn in getParent functions

parent 3459755d
......@@ -22,28 +22,30 @@ namespace Chill\PersonBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
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 Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Chill\MainBundle\Entity\GroupCenter;
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.
*
*
* 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)
* 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.
* - with the `role` option, only the people belonging to the reachable center for the
* given role are displayed.
*
*
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
......@@ -53,19 +55,19 @@ class PickPersonType extends AbstractType
* @var PersonRepository
*/
protected $personRepository;
/**
*
* @var \Chill\MainBundle\Entity\User
*/
protected $user;
/**
*
* @var AuthorizationHelper
*/
protected $authorizationHelper;
public function __construct(
PersonRepository $personRepository,
TokenStorageInterface $tokenStorage,
......@@ -76,21 +78,21 @@ class PickPersonType extends AbstractType
$this->user = $tokenStorage->getToken()->getUser();
$this->authorizationHelper = $authorizationHelper;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$qb = $options['query_builder'];
if ($options['role'] === NULL) {
$centers = array_map(function (GroupCenter $g) {
return $g->getCenter();
$centers = array_map(function (GroupCenter $g) {
return $g->getCenter();
}, $this->user->getGroupCenters()->toArray());
} else {
$centers = $this->authorizationHelper
->getReachableCenters($this->user, $options['role']);
}
if ($options['centers'] === NULL) {
// we select all selected centers
$selectedCenters = $centers;
......@@ -98,10 +100,10 @@ class PickPersonType extends AbstractType
$selectedCenters = array();
$options['centers'] = is_array($options['centers']) ?
$options['centers'] : array($options['centers']);
foreach ($options['centers'] as $c) {
// 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" '
. 'option must be an instance of '.Center::class);
}
......@@ -113,8 +115,8 @@ class PickPersonType extends AbstractType
$selectedCenters[] = $c;
}
}
$qb
->orderBy('p.firstName', 'ASC')
->orderBy('p.lastName', 'ASC')
......@@ -122,11 +124,11 @@ class PickPersonType extends AbstractType
->setParameter('centers', $selectedCenters)
;
}
public function configureOptions(OptionsResolver $resolver)
{
parent::configureOptions($resolver);
// add the possibles options for this type
$resolver->setDefined('centers')
->addAllowedTypes('centers', array('array', Center::class, 'null'))
......@@ -135,7 +137,7 @@ class PickPersonType extends AbstractType
->addAllowedTypes('role', array(Role::class, 'null'))
->setDefault('role', null)
;
// add the default options
$resolver->setDefaults(array(
'class' => Person::class,
......@@ -152,10 +154,10 @@ class PickPersonType extends AbstractType
'query_builder' => $this->personRepository->createQueryBuilder('p')
));
}
public function getParent()
{
return \Symfony\Bridge\Doctrine\Form\Type\EntityType::class;
return EntityType::class;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment