do not throw error when options are missing

This commit is contained in:
Julien Fastré 2017-08-19 20:15:57 +02:00
parent b5ad33e521
commit 1afcf75112

View File

@ -96,6 +96,8 @@ class PersonListWidget implements WidgetInterface
*/ */
public function render(\Twig_Environment $env, $place, array $context, array $config) public function render(\Twig_Environment $env, $place, array $context, array $config)
{ {
$numberOfItems = $config['number_of_items'] ?? 20;
$qb = $this->personRepository $qb = $this->personRepository
->createQueryBuilder('person'); ->createQueryBuilder('person');
@ -108,7 +110,7 @@ class PersonListWidget implements WidgetInterface
// add the "only active" query // add the "only active" query
if ($config['only_active'] === true) { if (\array_key_exists('only_active', $config) && $config['only_active'] === true) {
$qb->join('person.accompanyingPeriods', 'ap'); $qb->join('person.accompanyingPeriods', 'ap');
$or = new Expr\Orx(); $or = new Expr\Orx();
// add the case where closingDate IS NULL // add the case where closingDate IS NULL
@ -125,7 +127,7 @@ class PersonListWidget implements WidgetInterface
} }
if ($config['filtering_class'] !== NULL) { if (\array_key_exists('filtering_class', $config) && $config['filtering_class'] !== NULL) {
$filteringClass = new $config['filtering_class']; $filteringClass = new $config['filtering_class'];
if ( ! $filteringClass instanceof PersonListWidget\PersonFilteringInterface) { if ( ! $filteringClass instanceof PersonListWidget\PersonFilteringInterface) {
throw new \UnexpectedValueException(sprintf("the class %s does not " throw new \UnexpectedValueException(sprintf("the class %s does not "
@ -147,7 +149,7 @@ class PersonListWidget implements WidgetInterface
->addOrderBy('person.firstName', 'ASC'); ->addOrderBy('person.firstName', 'ASC');
$qb->setFirstResult(0)->setMaxResults($config['number_of_items']); $qb->setFirstResult(0)->setMaxResults($numberOfItems);
$persons = $qb->getQuery()->getResult(); $persons = $qb->getQuery()->getResult();