From 6b46410712c6fdf2ad44ca67a1b4aba88104b73c Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 8 Sep 2015 15:42:02 +0100 Subject: [PATCH] Issue #2538950 by alexpott, dawehner, stefan.r: Replace SafeMarkup::format() in template_preprocess_html with placeholders in the template --- core/includes/theme.inc | 20 ++++++++----------- core/modules/system/templates/html.html.twig | 17 ++++++---------- .../classy/templates/layout/html.html.twig | 17 ++++++---------- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 6f05be09ada3..7d157a9130d8 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1269,19 +1269,15 @@ function template_preprocess_html(&$variables) { // Create placeholder strings for these keys. // @see \Drupal\Core\Render\HtmlResponseSubscriber $types = [ - 'styles', - 'scripts', - 'scripts_bottom', - 'head', + 'styles' => 'css', + 'scripts' => 'js', + 'scripts_bottom' => 'js-bottom', + 'head' => 'head', ]; - $token = Crypt::randomBytesBase64(55); - foreach ($types as $type) { - $placeholder = SafeMarkup::format('', [ - '@type' => $type, - '@token' => $token, - ]); - $variables[$type]['#markup'] = $placeholder; - $variables[$type]['#attached']['html_response_attachment_placeholders'][$type] = $placeholder; + $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; } } diff --git a/core/modules/system/templates/html.html.twig b/core/modules/system/templates/html.html.twig index 4985973532ae..9039edc3c118 100644 --- a/core/modules/system/templates/html.html.twig +++ b/core/modules/system/templates/html.html.twig @@ -7,9 +7,6 @@ * - logged_in: A flag indicating if user is logged in. * - root_path: The root path of the current page (e.g., node, admin, user). * - node_type: The content type for the current node, if the page is a node. - * - css: A list of CSS files for the current page. - * - head: Markup for the HEAD element (including meta tags, keyword tags, and - * so on). * - head_title: List of text elements that make up the head_title variable. * May contain or more of the following: * - title: The title of the page. @@ -19,11 +16,9 @@ * - page: The rendered page markup. * - page_bottom: Closing rendered markup. This variable should be printed after * 'page'. - * - styles: HTML necessary to import all necessary CSS files in . - * - scripts: HTML necessary to load JavaScript files and settings in . - * - scripts_bottom: HTML necessary to load JavaScript files before closing - * tag. * - db_offline: A flag indicating if the database is offline. + * - placeholder_token: The token for generating head, css, js and js-bottom + * placeholders. * * @see template_preprocess_html() * @@ -33,10 +28,10 @@ - {{ head }} + {{ head_title|safe_join(' | ') }} - {{ styles }} - {{ scripts }} + + @@ -45,6 +40,6 @@ {{ page_top }} {{ page }} {{ page_bottom }} - {{ scripts_bottom }} + diff --git a/core/themes/classy/templates/layout/html.html.twig b/core/themes/classy/templates/layout/html.html.twig index 3911766bb31e..6c585b2de65c 100644 --- a/core/themes/classy/templates/layout/html.html.twig +++ b/core/themes/classy/templates/layout/html.html.twig @@ -7,9 +7,6 @@ * - logged_in: A flag indicating if user is logged in. * - root_path: The root path of the current page (e.g., node, admin, user). * - node_type: The content type for the current node, if the page is a node. - * - css: A list of CSS files for the current page. - * - head: Markup for the HEAD element (including meta tags, keyword tags, and - * so on). * - head_title: List of text elements that make up the head_title variable. * May contain or more of the following: * - title: The title of the page. @@ -19,11 +16,9 @@ * - page: The rendered page markup. * - page_bottom: Closing rendered markup. This variable should be printed after * 'page'. - * - styles: HTML necessary to import all necessary CSS files in . - * - scripts: HTML necessary to load JavaScript files and settings in . - * - scripts_bottom: HTML necessary to load JavaScript files before closing - * tag. * - db_offline: A flag indicating if the database is offline. + * - placeholder_token: The token for generating head, css, js and js-bottom + * placeholders. * * @see template_preprocess_html() */ @@ -39,10 +34,10 @@ - {{ head }} + {{ head_title|safe_join(' | ') }} - {{ styles }} - {{ scripts }} + +