diff --git a/Resources/views/Widget/homepage_person_list.html.twig b/Resources/views/Widget/homepage_person_list.html.twig
index a57b5e8ff..2be7d7885 100644
--- a/Resources/views/Widget/homepage_person_list.html.twig
+++ b/Resources/views/Widget/homepage_person_list.html.twig
@@ -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 %}
{{ 'Accompanyied people'|trans }}
diff --git a/Widget/PersonListWidget.php b/Widget/PersonListWidget.php
index dfebbdc00..b9ef18a4c 100644
--- a/Widget/PersonListWidget.php
+++ b/Widget/PersonListWidget.php
@@ -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
+
+ )
);
}
diff --git a/Widget/PersonListWidgetFactory.php b/Widget/PersonListWidgetFactory.php
index 760764fcb..d2237e11e 100644
--- a/Widget/PersonListWidgetFactory.php
+++ b/Widget/PersonListWidgetFactory.php
@@ -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()