diff --git a/core/includes/form.inc b/core/includes/form.inc index 03824f8..5b88317 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -2845,29 +2845,22 @@ function theme_form_required_marker($variables) { function template_preprocess_form_element_label(&$variables) { $element = $variables['element']; - // If title and required marker are both empty, output no label. - if ((!isset($element['#title']) || $element['#title'] === '') && empty($element['#required'])) { - $variables['value'] = '';; - } - else { - // If the element is required, a required marker is appended to the label. - $variables['required'] = !empty($element['#required']) ? theme('form_required_marker', array('element' => $element)) : ''; - - $variables['title'] = Xss::filterAdmin($element['#title']); + // If the element is required, a required marker is appended to the label. + $variables['required'] = !empty($element['#required']) ? theme('form_required_marker', array('element' => $element)) : ''; + $variables['title'] = (isset($element['#title']) && $element['#title'] !== '') ? Xss::filterAdmin($element['#title']) : ''; - $variables['attributes'] = array(); - // Style the label as class option to display inline with the element. - if ($element['#title_display'] == 'after') { - $variables['attributes']['class'][] = 'option'; - } - // Show label only to screen readers to avoid disruption in visual flows. - elseif ($element['#title_display'] == 'invisible') { - $variables['attributes']['class'][] = 'visually-hidden'; - } + $variables['attributes'] = array(); + // Style the label as class option to display inline with the element. + if ($element['#title_display'] == 'after') { + $variables['attributes']['class'][] = 'option'; + } + // Show label only to screen readers to avoid disruption in visual flows. + elseif ($element['#title_display'] == 'invisible') { + $variables['attributes']['class'][] = 'visually-hidden'; + } - if (!empty($element['#id'])) { - $variables['attributes']['for'] = $element['#id']; - } + if (!empty($element['#id'])) { + $variables['attributes']['for'] = $element['#id']; } } diff --git a/core/modules/system/templates/form-element-label.html.twig b/core/modules/system/templates/form-element-label.html.twig index f732943..bc96254 100644 --- a/core/modules/system/templates/form-element-label.html.twig +++ b/core/modules/system/templates/form-element-label.html.twig @@ -4,9 +4,16 @@ * Default theme implementation for a form element label. * * Available variables: + * - title: The label's text. + * - required: The required marker, or empty if the associated form element is + * not required. * - attributes: A list of HTML attributes for the label. * + * @see template_preprocess_form_element_label() + * * @ingroup themeable */ #} +{% if title or required %} {{ title }}{{ required }} +{% endif %}