function template_preprocess_form_element_label
Same name and namespace in other branches
- 10 core/includes/form.inc \template_preprocess_form_element_label()
- 9 core/includes/form.inc \template_preprocess_form_element_label()
- 8.9.x core/includes/form.inc \template_preprocess_form_element_label()
Prepares variables for form label templates.
Form element labels include the #title and a #required marker. The label is associated with the element itself by the element #id. Labels may appear before or after elements, depending on form-element.html.twig and #title_display.
This function will not be called for elements with no labels, depending on #title_display. For elements that have an empty #title and are not required, this function will output no label (''). For required elements that have an empty #title, this will output the required marker alone within the label. The label will use the #id to associate the marker with the field that is required. That is especially important for screen reader users to know which field is required.
To associate the label with a different field, set the #for property to the ID of the desired field.
Parameters
array $variables: An associative array containing:
- element: An associative array containing the properties of the element. Properties used: #required, #title, #id, #value, #description, #for.
Deprecated
in drupal:11.3.0 and is removed from drupal:12.0.0. Initial template_preprocess functions are registered directly in hook_theme().
See also
https://www.drupal.org/node/3504125
File
-
core/
includes/ form.inc, line 427
Code
function template_preprocess_form_element_label(&$variables) : void {
@trigger_error(__FUNCTION__ . '() is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Initial template_preprocess functions are registered directly in hook_theme(). See https://www.drupal.org/node/3504125', E_USER_DEPRECATED);
\Drupal::service(FormPreprocess::class)->preprocessFormElementLabel($variables);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.