sf4, remove deprecated use Symfony\Component\Form\ChoiceList\LazyChoiceList

This commit is contained in:
Tchama 2020-07-27 18:00:04 +02:00
parent 9952a885ed
commit 8d4d8f3a0d

View File

@ -1,4 +1,5 @@
<?php <?php
/* /*
* Copyright (C) 2018 Champs-Libres <info@champs-libres.coop> * Copyright (C) 2018 Champs-Libres <info@champs-libres.coop>
* *
@ -15,31 +16,43 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
namespace Chill\PersonBundle\Form\ChoiceLoader; namespace Chill\PersonBundle\Form\ChoiceLoader;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface; use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface; use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
/** /**
* Class PersonChoiceLoader
* *
* * @package Chill\PersonBundle\Form\ChoiceLoader
* @author Julien Fastré <julien.fastre@champs-libres.coop> * @author Julien Fastré <julien.fastre@champs-libres.coop>
*/ */
class PersonChoiceLoader implements ChoiceLoaderInterface class PersonChoiceLoader implements ChoiceLoaderInterface
{ {
/** /**
*
* @var EntityRepository * @var EntityRepository
*/ */
protected $personRepository; protected $personRepository;
/**
* @var array
*/
protected $lazyLoadedPersons = []; protected $lazyLoadedPersons = [];
/**
* @var array
*/
protected $centers = []; protected $centers = [];
/**
* PersonChoiceLoader constructor.
*
* @param EntityRepository $personRepository
* @param array|null $centers
*/
public function __construct( public function __construct(
EntityRepository $personRepository, EntityRepository $personRepository,
array $centers = null array $centers = null
@ -50,11 +63,18 @@ class PersonChoiceLoader implements ChoiceLoaderInterface
} }
} }
/**
* @return bool
*/
protected function hasCenterFilter() protected function hasCenterFilter()
{ {
return count($this->centers) > 0; return count($this->centers) > 0;
} }
/**
* @param null $value
* @return ChoiceListInterface
*/
public function loadChoiceList($value = null): ChoiceListInterface public function loadChoiceList($value = null): ChoiceListInterface
{ {
$list = new \Symfony\Component\Form\ChoiceList\ArrayChoiceList( $list = new \Symfony\Component\Form\ChoiceList\ArrayChoiceList(
@ -66,6 +86,11 @@ class PersonChoiceLoader implements ChoiceLoaderInterface
return $list; return $list;
} }
/**
* @param array $values
* @param null $value
* @return array
*/
public function loadChoicesForValues(array $values, $value = null) public function loadChoicesForValues(array $values, $value = null)
{ {
$choices = []; $choices = [];
@ -88,6 +113,11 @@ class PersonChoiceLoader implements ChoiceLoaderInterface
return $choices; return $choices;
} }
/**
* @param array $choices
* @param null $value
* @return array|string[]
*/
public function loadValuesForChoices(array $choices, $value = null) public function loadValuesForChoices(array $choices, $value = null)
{ {
$values = []; $values = [];