I am trying to customize Symfony form label to add an asterisk(*) for all required fields through this Symfony doc. But my asterisk <span has to be inside the <label tag so I had to customize form_label block as described here. So far is good, but the customization also being applied to each item(label) of checkbox/radio fields. where it looks odd.
Any idea, how could I filter it in label customized block to format only for parent labels.
Here is my overridden code :
{% block form_label -%}
{% if label is not sameas(false) -%}
{% if not compound -%}
{% set label_attr = label_attr|merge({'for': id}) %}
{%- endif %}
{% if required -%}
{% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
{%- endif %}
{% if label is empty -%}
{% set label = name|humanize %}
{%- endif -%}
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
{{ label|trans({}, translation_domain) }}
{% if required %} <span class="required" title="This field is required">*</span> {% endif %}
</label>
{%- endif %}
{%- endblock form_label %}
In brief, I want a variable inside this block to identify the field type this label is targeting to.