mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-18 08:14:24 +00:00
Only display active custom fields in form & view
This commit is contained in:
parent
9f98c4e7e6
commit
101783b9f1
@ -46,10 +46,10 @@ class CustomFieldType extends AbstractType
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
foreach ($options['group']->getCustomFields() as $cf) {
|
||||
foreach ($options['group']->getActiveCustomFields() as $cf) {
|
||||
$this->customFieldCompiler
|
||||
->getCustomFieldByType($cf->getType())
|
||||
->buildForm($builder, $cf);
|
||||
->getCustomFieldByType($cf->getType())
|
||||
->buildForm($builder, $cf);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ services:
|
||||
- "@chill.main.helper.translatable_string"
|
||||
tags:
|
||||
- { name: 'chill.custom_field', type: 'choice' }
|
||||
|
||||
|
||||
chill.custom_field.custom_fields_group_linked_custom_fields:
|
||||
class: Chill\CustomFieldsBundle\Form\Type\LinkedCustomFieldsType
|
||||
arguments:
|
||||
@ -82,3 +82,10 @@ services:
|
||||
- [setContainer, ["@service_container"]]
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
|
||||
chill.custom_field.twig.custom_fields_group_rendering:
|
||||
class: Chill\CustomFieldsBundle\Templating\Twig\CustomFieldsGroupRenderingTwig
|
||||
calls:
|
||||
- [setContainer, ["@service_container"]]
|
||||
tags:
|
||||
- { name: twig.extension }
|
8
Resources/views/CustomFieldsGroup/render.html.twig
Normal file
8
Resources/views/CustomFieldsGroup/render.html.twig
Normal file
@ -0,0 +1,8 @@
|
||||
{% for customField in cFGroup.activeCustomFields %}
|
||||
{% if customField.type == 'title' %}
|
||||
{{ chill_custom_field_widget(cFData , customField) }}
|
||||
{% else %}
|
||||
<dt>{{ chill_custom_field_label(customField) }}</dt>
|
||||
<dd>{{ chill_custom_field_widget(cFData , customField) }}</dd>
|
||||
{% endif %}
|
||||
{% endfor %}
|
107
Templating/Twig/CustomFieldsGroupRenderingTwig.php
Normal file
107
Templating/Twig/CustomFieldsGroupRenderingTwig.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
namespace Chill\CustomFieldsBundle\Templating\Twig;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
|
||||
/**
|
||||
* Add the following Twig Extension :
|
||||
* * chill_custom_fields_group_widget : to render the value of a custom field
|
||||
* * group
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* @author Marc Ducobu <marc.ducobu@champs-libres.coop>
|
||||
*/
|
||||
class CustomFieldsGroupRenderingTwig extends \Twig_Extension implements ContainerAwareInterface
|
||||
{
|
||||
|
||||
/** @var Container $container The container */
|
||||
private $container;
|
||||
|
||||
/** @var array $defaultParams The default parameters */
|
||||
private $defaultParams = array(
|
||||
'layout' => 'ChillCustomFieldsBundle:CustomFieldsGroup:render.html.twig'
|
||||
);
|
||||
|
||||
/*
|
||||
* (non-PHPdoc)
|
||||
* @see \Symfony\Component\DependencyInjection\ContainerAwareInterface::setContainer()
|
||||
*/
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-PHPdoc)
|
||||
* @see Twig_Extension::getFunctions()
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new \Twig_SimpleFunction('chill_custom_fields_group_widget', array(
|
||||
$this,
|
||||
'renderWidget'
|
||||
), array(
|
||||
'is_safe' => array(
|
||||
'html'
|
||||
)
|
||||
)),
|
||||
];
|
||||
}
|
||||
|
||||
/* (non-PHPdoc)
|
||||
* @see Twig_ExtensionInterface::getName()
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'chill_custom_fields_group_rendering';
|
||||
}
|
||||
|
||||
/**
|
||||
* Twig extension that is used to render the value of a custom field group.
|
||||
*
|
||||
* The presentation of the value is influenced by the document type.
|
||||
*
|
||||
* @param array $fields The array raw, as stored in the db
|
||||
* @param CustomFieldsGroud $customFielsGroup The custom field group
|
||||
* @param string $documentType The type of the document (csv, html)
|
||||
* @param array $params The parameters for rendering :
|
||||
* - layout : allow to choose a different layout by default :
|
||||
* ChillCustomFieldsBundle:CustomFieldsGroup:render.html.twig
|
||||
* @return string HTML representation of the custom field group value, as described in
|
||||
* the CustomFieldInterface. Is HTML safe
|
||||
*/
|
||||
public function renderWidget(array $fields, $customFielsGroup, $documentType='html', array $params = array())
|
||||
{
|
||||
$resolvedParams = array_merge($this->defaultParams, $params);
|
||||
|
||||
return $this->container->get('templating')
|
||||
->render($resolvedParams['layout'], array(
|
||||
'cFGroup' => $customFielsGroup,
|
||||
'cFData' => $fields));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user