From 8dddf90838fd576bba86213c36696d11a0f8b1e8 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Fri, 18 Dec 2020 17:51:43 +0100 Subject: [PATCH] :recycle: new var_export filter for bolean values --- sources/application/TwigBase/Twig/Extension.php | 4 ++++ templates/base/components/field/layout.html.twig | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sources/application/TwigBase/Twig/Extension.php b/sources/application/TwigBase/Twig/Extension.php index 511b7446e..2feea82a6 100644 --- a/sources/application/TwigBase/Twig/Extension.php +++ b/sources/application/TwigBase/Twig/Extension.php @@ -136,6 +136,10 @@ class Extension }) ); + // var_export can be used for example to transform a PHP boolean to 'true' or 'false' strings + // @see https://www.php.net/manual/fr/function.var-export.php + $oTwigEnv->addFilter(new Twig_SimpleFilter('var_export', 'var_export')); + // Function to check our current environment // Usage in twig: {% if is_development_environment() %} diff --git a/templates/base/components/field/layout.html.twig b/templates/base/components/field/layout.html.twig index 84a53adf4..4c115b92b 100644 --- a/templates/base/components/field/layout.html.twig +++ b/templates/base/components/field/layout.html.twig @@ -7,12 +7,12 @@ {# Note: This might not the best way to this, we might rather have some properties for this flags in te Field class. #} {# For the moment this just aims at restoring the metadata introduced in iTop 2.7. Refactoring the Field class with specialization for each type must be designed by all the team #} {# as we might want to re-use / adapt the Field classes introduced with the end-user portal #} - data-attribute-flag-hidden="{% if oUIBlock.IsHidden() %}true{% else %}false{% endif %}" - data-attribute-flag-read-only="{% if oUIBlock.IsReadOnly() %}true{% else %}false{% endif %}" - data-attribute-flag-mandatory="{% if oUIBlock.IsMandatory() %}true{% else %}false{% endif %}" - data-attribute-flag-must-change="{% if oUIBlock.IsMustChange() %}true{% else %}false{% endif %}" - data-attribute-flag-must-prompt="{% if oUIBlock.IsMustPrompt() %}true{% else %}false{% endif %}" - data-attribute-flag-slave="{% if oUIBlock.IsSlave() %}true{% else %}false{% endif %}" + data-attribute-flag-hidden="{{ oUIBlock.IsHidden()|var_export }}" + data-attribute-flag-read-only="{{ oUIBlock.IsReadOnly()|var_export }}" + data-attribute-flag-mandatory="{{ oUIBlock.IsMandatory()|var_export }}" + data-attribute-flag-must-change="{{ oUIBlock.IsMustChange()|var_export }}" + data-attribute-flag-must-prompt="{{ oUIBlock.IsMustPrompt()|var_export }}" + data-attribute-flag-slave="{{ oUIBlock.IsSlave()|var_export }}" data-value-raw="{{ aParams.value_raw }}" >
{{ oUIBlock.GetLabel()|raw }}