mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
allow to pass customfields to person list widget
This commit is contained in:
parent
771fa68c2f
commit
90ced95a4b
@ -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 %}
|
{% import 'ChillPersonBundle:Person:macro.html.twig' as person %}
|
||||||
<div class="grid-8 centered">
|
<div class="grid-8 centered">
|
||||||
<h2>{{ 'Accompanyied people'|trans }}</h2>
|
<h2>{{ 'Accompanyied people'|trans }}</h2>
|
||||||
|
@ -29,11 +29,15 @@ use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
|
|||||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||||
use Symfony\Component\Security\Core\Role\Role;
|
use Symfony\Component\Security\Core\Role\Role;
|
||||||
use Doctrine\ORM\EntityManager;
|
use Doctrine\ORM\EntityManager;
|
||||||
|
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add a widget with person list.
|
* add a widget with person list.
|
||||||
*
|
*
|
||||||
* The configuration is defined by `PersonListWidgetFactory`
|
* 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
|
class PersonListWidget implements WidgetInterface
|
||||||
{
|
{
|
||||||
@ -147,9 +151,28 @@ class PersonListWidget implements WidgetInterface
|
|||||||
|
|
||||||
$persons = $qb->getQuery()->getResult();
|
$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(
|
return $env->render(
|
||||||
'ChillPersonBundle:Widget:homepage_person_list.html.twig',
|
'ChillPersonBundle:Widget:homepage_person_list.html.twig',
|
||||||
array('persons' => $persons)
|
array(
|
||||||
|
'persons' => $persons,
|
||||||
|
'customFields' => $cfields
|
||||||
|
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,13 @@ class PersonListWidgetFactory extends AbstractWidgetFactory
|
|||||||
$node->scalarNode('filtering_class')
|
$node->scalarNode('filtering_class')
|
||||||
->defaultNull()
|
->defaultNull()
|
||||||
->end();
|
->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()
|
public function getAllowedPlaces()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user