allow to pass customfields to person list widget

This commit is contained in:
Julien Fastré 2016-10-20 12:10:52 +02:00
parent 771fa68c2f
commit 90ced95a4b
3 changed files with 35 additions and 2 deletions

View File

@ -1,3 +1,7 @@
{#
if the `custom_fields` option is used, the custom fields are available
under the customFields variable, with the custom field slug as key.
#}
{% import 'ChillPersonBundle:Person:macro.html.twig' as person %}
<div class="grid-8 centered">
<h2>{{ 'Accompanyied people'|trans }}</h2>

View File

@ -29,11 +29,15 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Symfony\Component\Security\Core\Role\Role;
use Doctrine\ORM\EntityManager;
use Chill\CustomFieldsBundle\Entity\CustomField;
/**
* add a widget with person list.
*
* The configuration is defined by `PersonListWidgetFactory`
*
* If the options 'custom_fields' is used, the custom fields entity will be
* queried from the db and transmitted to the view under the `customFields` variable.
*/
class PersonListWidget implements WidgetInterface
{
@ -147,9 +151,28 @@ class PersonListWidget implements WidgetInterface
$persons = $qb->getQuery()->getResult();
// get some custom field when the view is overriden and we want to
// show some custom field in the overriden view.
$cfields = array();
if (isset($config['custom_fields'])) {
if (count($config['custom_fields']) > 0) {
$cfs = $this->entityManager
->getRepository('ChillCustomFieldsBundle:CustomField')
->findBy(array('slug' => $config['custom_fields']));
// store the custom fields in a array
foreach($cfs as $cf) {
$cfields[$cf->getSlug()] = $cf;
}
}
}
return $env->render(
'ChillPersonBundle:Widget:homepage_person_list.html.twig',
array('persons' => $persons)
array(
'persons' => $persons,
'customFields' => $cfields
)
);
}

View File

@ -39,7 +39,13 @@ class PersonListWidgetFactory extends AbstractWidgetFactory
$node->scalarNode('filtering_class')
->defaultNull()
->end();
$node->arrayNode('custom_fields')
->prototype('scalar')->end()
->info("Add some custom field to the view. Add the slug of some custom field"
. " if you want to override the view and show their value in the list")
->example(array("custom-field-slug-1", "custom-field-slug-2"))
->cannotBeEmpty()
->end();
}
public function getAllowedPlaces()