function template_preprocess_fieldset in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/includes/form.inc \template_preprocess_fieldset()
Prepares variables for fieldset element templates.
Default template: fieldset.html.twig.
Parameters
array $variables: An associative array containing:
- element: An associative array containing the properties of the element. Properties used: #attributes, #children, #description, #id, #title, #value.
File
- core/
includes/ form.inc, line 191 - Functions for form and batch generation and processing.
Code
function template_preprocess_fieldset(&$variables) {
$element = $variables['element'];
Element::setAttributes($element, array(
'id',
));
Element\RenderElement::setAttributes($element);
$variables['attributes'] = $element['#attributes'];
$variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL;
$variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL;
$variables['title_display'] = isset($element['#title_display']) ? $element['#title_display'] : NULL;
$variables['children'] = $element['#children'];
$variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;
if (isset($element['#title']) && $element['#title'] !== '') {
$variables['legend']['title'] = [
'#markup' => $element['#title'],
];
}
$variables['legend']['attributes'] = new Attribute();
$variables['legend_span']['attributes'] = new Attribute();
if (!empty($element['#description'])) {
$description_id = $element['#attributes']['id'] . '--description';
$description_attributes['id'] = $description_id;
$variables['description']['attributes'] = new Attribute($description_attributes);
$variables['description']['content'] = $element['#description'];
// Add the description's id to the fieldset aria attributes.
$variables['attributes']['aria-describedby'] = $description_id;
}
// Suppress error messages.
$variables['errors'] = NULL;
}