From 9749ce619406b7cd3583fd625e845881734483ed Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 9 Jan 2021 19:45:49 +0100 Subject: [PATCH 1/3] Added option 'twig' to form field to evaluate label using twig. --- templates/forms/default/field.html.twig | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/forms/default/field.html.twig b/templates/forms/default/field.html.twig index faa00949..b4b25ecd 100644 --- a/templates/forms/default/field.html.twig +++ b/templates/forms/default/field.html.twig @@ -58,7 +58,8 @@ {% set layout_form_field_outer_classes = layout_form_field_outer_classes|trim ~ ' ' ~ embed_outer_field_classes %} {# Show Label logic #} -{% set show_label = field.label is not same as(false) and field.display_label is not same as(false )%} +{% set form_field_label = form_field_label ?? field.label %} +{% set show_label = form_field_label is not same as(false) and field.display_label is not same as(false )%} {# Label Classes #} {% set layout_form_field_outer_label_classes = ((form_field_outer_label_classes ?: 'form-label') ~ ' ' ~ field.labelclasses)|trim %} @@ -91,7 +92,8 @@ {% set form_field_for = toggleable ? 'toggleable_' ~ field.name : field.id|e %} {# Field Label #} -{% set form_field_label = field.markdown ? field.label|markdown(false) : field.label %} +{% set form_field_label = field.markdown ? form_field_label|markdown(false) : form_field_label %} +{% set form_field_label = field.twig ? evaluate_twig(form_field_label) : form_field_label %} {% set form_field_label = form_field_label|default(field.name|capitalize)|t %} {# Field Help #} From a96ea62e5e0b0492baf4a97b43509d09d026c13f Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 9 Jan 2021 20:21:48 +0100 Subject: [PATCH 2/3] Do not let field label be overwritten by external variable, as it would break sections --- templates/forms/default/field.html.twig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/forms/default/field.html.twig b/templates/forms/default/field.html.twig index b4b25ecd..ecc1d045 100644 --- a/templates/forms/default/field.html.twig +++ b/templates/forms/default/field.html.twig @@ -58,8 +58,7 @@ {% set layout_form_field_outer_classes = layout_form_field_outer_classes|trim ~ ' ' ~ embed_outer_field_classes %} {# Show Label logic #} -{% set form_field_label = form_field_label ?? field.label %} -{% set show_label = form_field_label is not same as(false) and field.display_label is not same as(false )%} +{% set show_label = field.label is not same as(false) and field.display_label is not same as(false )%} {# Label Classes #} {% set layout_form_field_outer_label_classes = ((form_field_outer_label_classes ?: 'form-label') ~ ' ' ~ field.labelclasses)|trim %} @@ -92,6 +91,7 @@ {% set form_field_for = toggleable ? 'toggleable_' ~ field.name : field.id|e %} {# Field Label #} +{% set form_field_label = field.label %} {% set form_field_label = field.markdown ? form_field_label|markdown(false) : form_field_label %} {% set form_field_label = field.twig ? evaluate_twig(form_field_label) : form_field_label %} {% set form_field_label = form_field_label|default(field.name|capitalize)|t %} From 68c1920b5485a1cbc528ff1c1332dfc2a9b1b5ac Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 9 Jan 2021 20:36:42 +0100 Subject: [PATCH 3/3] Added markdown and twig support for section text field --- templates/forms/fields/section/section.html.twig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/forms/fields/section/section.html.twig b/templates/forms/fields/section/section.html.twig index d3e9fe05..30cca16d 100644 --- a/templates/forms/fields/section/section.html.twig +++ b/templates/forms/fields/section/section.html.twig @@ -9,7 +9,10 @@ {% endif %} {% if field.text %} -

{{ field.text|t|raw }}

+ {% set field_text = field.text %} + {% set field_text = field.markdown ? field_text|markdown(false) : field_text %} + {% set field_text = field.twig ? evaluate_twig(field_text) : field_text %} +

{{ field_text|t|raw }}

{% endif %} {% if field.fields %}