semanticui-8.x-1.x-dev/templates/form/form-element-label.html.twig
templates/form/form-element-label.html.twig
{#
/**
* @file
* Theme override for a form element label.
*
* Available variables:
* - title: The label's text.
* - title_display: Elements title_display setting.
* - required: An indicator for whether the associated form element is required.
* - attributes: A list of HTML attributes for the label.
*
* @see template_preprocess_form_element_label()
*/
#}
{%
set classes = [
title_display == 'after' ? 'option',
title_display == 'invisible' and not element['#is_checkbox'] ? 'visually-hidden',
required ? 'js-form-required',
]
%}
{# Move label title to attribute so it's accessible by screen readers. #}
{% if title is not empty and title_display == 'invisible' and element['#is_checkbox'] %}
{% set attributes = attributes.setAttribute('title', title) %}
{% set title = null %}
{% endif %}
{% if title is not empty or required or element['#is_checkbox'] -%}
<label{{ attributes.addClass(classes) }}>{{ title }}</label>
{%- endif %}
