template_preprocess_html(&$variables)
Prepares variables for HTML document templates.
Default template: html.html.twig.
Parameters
array $variables: An associative array containing:
- page: A render element representing the page.
File
- core/includes/theme.inc, line 1254
- The theme system, which controls the output of Drupal.
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | function template_preprocess_html(& $variables ) { $variables [ 'page' ] = $variables [ 'html' ][ 'page' ]; unset( $variables [ 'html' ][ 'page' ]); $variables [ 'page_top' ] = NULL; if (isset( $variables [ 'html' ][ 'page_top' ])) { $variables [ 'page_top' ] = $variables [ 'html' ][ 'page_top' ]; unset( $variables [ 'html' ][ 'page_top' ]); } $variables [ 'page_bottom' ] = NULL; if (isset( $variables [ 'html' ][ 'page_bottom' ])) { $variables [ 'page_bottom' ] = $variables [ 'html' ][ 'page_bottom' ]; unset( $variables [ 'html' ][ 'page_bottom' ]); } $variables [ 'html_attributes' ] = new Attribute(); // <html> element attributes. $language_interface = \Drupal::languageManager()->getCurrentLanguage(); $variables [ 'html_attributes' ][ 'lang' ] = $language_interface ->getId(); $variables [ 'html_attributes' ][ 'dir' ] = $language_interface ->getDirection(); if (isset( $variables [ 'db_is_active' ]) && ! $variables [ 'db_is_active' ]) { $variables [ 'db_offline' ] = TRUE; } // Add a variable for the root path. This can be used to create a class and // theme the page depending on the current path (e.g. node, admin, user) as // well as more specific data like path-frontpage. $is_front_page = \Drupal::service( 'path.matcher' )->isFrontPage(); if ( $is_front_page ) { $variables [ 'root_path' ] = FALSE; } else { $system_path = \Drupal::service( 'path.current' )->getPath(); $variables [ 'root_path' ] = explode ( '/' , $system_path ) [1]; } $site_config = \Drupal::config( 'system.site' ); // Construct page title. if (isset( $variables [ 'page' ][ '#title' ]) && is_array ( $variables [ 'page' ][ '#title' ])) { // Do an early render if the title is a render array. $variables [ 'page' ][ '#title' ] = (string) \Drupal::service( 'renderer' )->render( $variables [ 'page' ][ '#title' ]); } if (! empty ( $variables [ 'page' ][ '#title' ])) { $head_title = array ( // Marking the title as safe since it has had the tags stripped. 'title' => Markup::create(trim( strip_tags ( $variables [ 'page' ][ '#title' ]))), 'name' => $site_config ->get( 'name' ), ); } // @todo Remove once views is not bypassing the view subscriber anymore. elseif ( $is_front_page ) { $head_title = array ( 'title' => t( 'Home' ), 'name' => $site_config ->get( 'name' ), ); } else { $head_title = [ 'name' => $site_config ->get( 'name' )]; if ( $site_config ->get( 'slogan' )) { $head_title [ 'slogan' ] = strip_tags ( $site_config ->get( 'slogan' )); } } $variables [ 'head_title' ] = $head_title ; // @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. $variables [ 'head_title_array' ] = $head_title ; // Create placeholder strings for these keys. // @see \Drupal\Core\Render\HtmlResponseSubscriber $types = [ 'styles' => 'css' , 'scripts' => 'js' , 'scripts_bottom' => 'js-bottom' , 'head' => 'head' , ]; $variables [ 'placeholder_token' ] = Crypt::randomBytesBase64(55); foreach ( $types as $type => $placeholder_name ) { $placeholder = '<' . $placeholder_name . '-placeholder token="' . $variables [ 'placeholder_token' ] . '">' ; $variables [ '#attached' ][ 'html_response_attachment_placeholders' ][ $type ] = $placeholder ; } } |
Please login to continue.