template_preprocess_fieldset(&$variables)
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 192
- Functions for form and batch generation and processing.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | function template_preprocess_fieldset(& $variables ) { $element = $variables [ 'element' ]; Element::setAttributes( $element , array ( 'id' )); RenderElement::setAttributes( $element ); $variables [ 'attributes' ] = isset( $element [ '#attributes' ]) ? $element [ '#attributes' ] : array (); $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(); // Add 'visually-hidden' class to legend span. if ( $variables [ 'title_display' ] == 'invisible' ) { $variables [ 'legend_span' ][ 'attributes' ] = new Attribute( array ( 'class' => 'visually-hidden' )); } else { $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; } |
Please login to continue.