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 (!empty($variables['page']['#title'])) { $head_title = array( 'title' => trim(strip_tags($variables['page']['#title'])), 'name' => $site_config->get('name'), ); } // @todo Remove once views is not bypassing the view subscriber anymore. // @see https://www.drupal.org/node/2068471 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; // Collect all attachments. This must happen in the preprocess function for // #type => html, to ensure that attachments added in #pre_render callbacks // for #type => html are included. $attached = $variables['html']['#attached']; $attached = drupal_merge_attached($attached, $variables['page']['#attached']); if (isset($variables['page_top'])) { $attached = drupal_merge_attached($attached, $variables['page_top']['#attached']); } if (isset($variables['page_bottom'])) { $attached = drupal_merge_attached($attached, $variables['page_bottom']['#attached']); } // Render the attachments into HTML markup to be used directly in the template // for #type => html: html.html.twig. $all_attached = ['#attached' => $attached]; $assets = AttachedAssets::createFromRenderArray($all_attached); // Take Ajax page state into account, to allow for something like Turbolinks // to be implemented without altering core. // @see https://github.com/rails/turbolinks/ $ajax_page_state = \Drupal::request()->request->get('ajax_page_state'); $assets->setAlreadyLoadedLibraries(isset($ajax_page_state) ? explode(',', $ajax_page_state['libraries']) : []); // Optimize CSS/JS if necessary, but only during normal site operation. $optimize_css = !defined('MAINTENANCE_MODE') && \Drupal::config('system.performance')->get('css.preprocess'); $optimize_js = !defined('MAINTENANCE_MODE') && \Drupal::config('system.performance')->get('js.preprocess'); // Render the asset collections. $asset_resolver = \Drupal::service('asset.resolver'); $variables['styles'] = \Drupal::service('asset.css.collection_renderer')->render($asset_resolver->getCssAssets($assets, $optimize_css)); list($js_assets_header, $js_assets_footer) = $asset_resolver->getJsAssets($assets, $optimize_js); $js_collection_renderer = \Drupal::service('asset.js.collection_renderer'); $variables['scripts'] = $js_collection_renderer->render($js_assets_header); $variables['scripts_bottom'] = $js_collection_renderer->render($js_assets_footer); // Also create the alternative version of the aggregate that is unoptimized, // but annotated with deep links to the license information on the // JavaScript License Web Labels page. // @see \Drupal\system\Controller\AssetLicenseInfoController \Drupal::service('asset.js.collection_optimizer_license_web_labels_annotator')->optimize($js_assets_header); \Drupal::service('asset.js.collection_optimizer_license_web_labels_annotator')->optimize($js_assets_footer); // Handle all non-asset attachments. drupal_process_attached($all_attached); $variables['head'] = drupal_get_html_head(FALSE); }