From 9c622bc852664c2f039d50e85d28f9068d2ffb24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 17 Dec 2015 07:41:16 +0100 Subject: [PATCH] improve cfgroup rendering to show title only if necessary If the value `chill_custom_fields.show_empty_values_in_views` is false, the title is shown only if a field has been filled "below" the title. --- Resources/translations/messages.fr.yml | 4 ++ .../views/CustomFieldsGroup/render.html.twig | 39 +++++++++++++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index f77f08028..bf29b6e7b 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -2,6 +2,10 @@ 'Other value': 'Autre valeur' 'None': 'Pas spécifié' +#customfieldsgroup rendering +Empty data: Données vides +No data to show: Pas de valeurs à afficher + #customfieldsgroup administration CustomFieldsGroup list: Groupes de champs personnalisés CustomFieldsGroup creation: Nouveau groupe de champs personnalisés diff --git a/Resources/views/CustomFieldsGroup/render.html.twig b/Resources/views/CustomFieldsGroup/render.html.twig index e325432a0..fb293cf92 100644 --- a/Resources/views/CustomFieldsGroup/render.html.twig +++ b/Resources/views/CustomFieldsGroup/render.html.twig @@ -1,10 +1,43 @@ +{#- a customField element will be stored in title variable -#} +{%- set title = null -%} +{#- a customField element will be stored in subtitle variable -#} +{%- set subtitle = null -%} +{%- set type = constant('Chill\\CustomFieldsBundle\\CustomFields\\CustomFieldTitle::TYPE') -%} +{%- set type_subtitle = constant('Chill\\CustomFieldsBundle\\CustomFields\\CustomFieldTitle::TYPE_SUBTITLE') -%} +{%- set type_title = constant('Chill\\CustomFieldsBundle\\CustomFields\\CustomFieldTitle::TYPE_TITLE') -%} +{# a variable to store that "something has been printed #} +{%- set something_has_been_printed = false -%} {% for customField in cFGroup.activeCustomFields %} {% if customField.type == 'title' %} + {%- if show_empty == true %} {{ chill_custom_field_widget(cFData , customField) }} + {%- else -%} + {# we keep the customfield in memory, and print it only if 'something' has been filled after the title #} + {%- if customField.options[type] == type_title -%} + {%- set title = customField -%} + {# we have to reset the title hierarchy if we misused titles hierarchy #} + {%- set subtitle = null -%} + {%- elseif customField.options[type] == type_subtitle -%} + {%- set subtitle = customField -%} + {%- endif -%} + {%- endif -%} {% else %} {%- if show_empty == true or (chill_custom_field_is_empty(customField, cFData) == false) -%} -
{{ chill_custom_field_label(customField) }}
-
{{ chill_custom_field_widget(cFData , customField) }}
+ {%- if title is not empty -%} + {{ chill_custom_field_widget(cFData, title) }} + {%- set title = null -%} + {%- endif -%} + {%- if subtitle is not empty -%} + {{ chill_custom_field_widget(cFData, subtitle) }} + {%- set subtitle = null -%} + {%- endif -%} +
{{ chill_custom_field_label(customField) }}
+
{{ chill_custom_field_widget(cFData , customField) }}
+ {%- set something_has_been_printed = true -%} {%- endif -%} {%- endif -%} -{% endfor %} \ No newline at end of file +{% endfor %} +{% if something_has_been_printed == false %} +
{{ 'Empty data'|trans }}
+
{{ 'No data to show' | trans }}
+{% endif %} \ No newline at end of file