-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathform-element-label.html.twig
More file actions
50 lines (48 loc) · 1.63 KB
/
form-element-label.html.twig
File metadata and controls
50 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{#
/**
* @file
* Default theme implementation for a form element label.
*
* Available variables:
* - element: an input element.
* - title: The label's text.
* - title_display: Elements title_display setting.
* - description: element description.
* - required: An indicator for whether the associated form element is required.
* - is_checkbox: Whether the label is outputted in checkbox context.
* - is_radio: Whether the label is outputted in radio button context.
* - attributes: A list of HTML attributes for the label.
*
* @ingroup templates
*
* @see template_preprocess_form_element_label()
*/
#}
{%-
set classes = [
title_display == 'after' ? 'option',
title_display == 'invisible' and not (is_checkbox or is_radio) ? 'sr-only',
required and not (is_checkbox or is_radio) ? 'required'
]
-%}
{% if title is not empty and title_display == 'invisible' and (is_checkbox or is_radio) -%}
{# Make invisible labels for checkboxes/radios to make them screen-reader friendly #}
{%- set attributes = attributes.setAttribute('title', title) -%}
{%- set title = null -%}
{%- endif -%}
{#
Labels for single checkboxes/radios contain the element itself and thus have
always to be rendered regardless of whether they have a title or not.
#}
{%- if title is not empty or is_checkbox or is_radio -%}
<label{{ attributes.addClass(classes) }}>
{{ element }}
<span class="field-name">{{ title }}</span>
{% if required %}
<strong class="required" aria-hidden="true">({{ 'required'|t }})</strong>
{% endif %}
{% if description %}
<p class="help-block">{{ description }}</p>
{% endif %}
</label>
{%- endif -%}