template_preprocess_toolbar(&$variables)
Prepares variables for administration toolbar templates.
Default template: toolbar.html.twig.
Parameters
array $variables: An associative array containing:
- element: An associative array containing the properties and children of the tray. Properties used: #children, #attributes and #bar.
File
- core/modules/toolbar/toolbar.module, line 76
- Administration toolbar for quick access to top level administration items.
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | function template_preprocess_toolbar(& $variables ) { $element = $variables [ 'element' ]; // Prepare the toolbar attributes. $variables [ 'attributes' ] = $element [ '#attributes' ]; $variables [ 'toolbar_attributes' ] = new Attribute( $element [ '#bar' ][ '#attributes' ]); $variables [ 'toolbar_heading' ] = $element [ '#bar' ][ '#heading' ]; // Prepare the trays and tabs for each toolbar item as well as the remainder // variable that will hold any non-tray, non-tab elements. $variables [ 'trays' ] = array (); $variables [ 'tabs' ] = array (); $variables [ 'remainder' ] = array (); foreach (Element::children( $element ) as $key ) { // Early rendering to collect the wrapper attributes from // ToolbarItem elements. if (! empty ( $element [ $key ])) { Drupal::service( 'renderer' )->render( $element [ $key ]); } // Add the tray. if (isset( $element [ $key ][ 'tray' ])) { $attributes = array (); if (! empty ( $element [ $key ][ 'tray' ][ '#wrapper_attributes' ])) { $attributes = $element [ $key ][ 'tray' ][ '#wrapper_attributes' ]; } $variables [ 'trays' ][ $key ] = array ( 'links' => $element [ $key ][ 'tray' ], 'attributes' => new Attribute( $attributes ), ); if ( array_key_exists ( '#heading' , $element [ $key ][ 'tray' ])) { $variables [ 'trays' ][ $key ][ 'label' ] = $element [ $key ][ 'tray' ][ '#heading' ]; } } // Add the tab. if (isset( $element [ $key ][ 'tab' ])) { $attributes = array (); // Pass the wrapper attributes along. if (! empty ( $element [ $key ][ '#wrapper_attributes' ])) { $attributes = $element [ $key ][ '#wrapper_attributes' ]; } $variables [ 'tabs' ][ $key ] = array ( 'link' => $element [ $key ][ 'tab' ], 'attributes' => new Attribute( $attributes ), ); } // Add other non-tray, non-tab child elements to the remainder variable for // later rendering. foreach (Element::children( $element [ $key ]) as $child_key ) { if (!in_array( $child_key , array ( 'tray' , 'tab' ))) { $variables [ 'remainder' ][ $key ][ $child_key ] = $element [ $key ][ $child_key ]; } } } } |
Please login to continue.