4 * Default theme implementation for a form element label.
7 * - element: an input element.
8 * - title: The label's text.
9 * - title_display: Elements title_display setting.
10 * - description: element description.
11 * - required: An indicator for whether the associated form element is required.
12 * - is_checkbox: Whether the label is outputted in checkbox context.
13 * - is_radio: Whether the label is outputted in radio button context.
14 * - attributes: A list of HTML attributes for the label.
18 * @see template_preprocess_form_element_label()
24 title_display == 'after' ? 'option',
25 title_display == 'invisible' and not (is_checkbox or is_radio) ? 'sr-only',
26 required ? 'js-form-required',
27 required ? 'form-required',
30 {% if title is not empty and title_display == 'invisible' and (is_checkbox or is_radio) -%}
32 Clear but preserve label text as attribute (e.g. for screen readers) for
33 checkboxes/radio buttons when it actually should be invisible.
35 {%- set attributes = attributes.setAttribute('title', title) -%}
36 {%- set title = null -%}
39 Labels for single checkboxes/radios contain the element itself and thus have
40 always to be rendered regardless of whether they have a title or not.
42 {%- if title is not empty or is_checkbox or is_radio -%}
43 <label{{ attributes.addClass(classes) }}>{{ element }}{{ title }}
44 {%- if description -%}
45 <p class="help-block">{{ description }}</p>