Commit 6b464107 authored by catch's avatar catch

Issue #2538950 by alexpott, dawehner, stefan.r: Replace SafeMarkup::format()...

Issue #2538950 by alexpott, dawehner, stefan.r: Replace SafeMarkup::format() in template_preprocess_html with placeholders in the template
parent 4c7b4763
......@@ -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('<drupal-html-response-attachment-placeholder type="@type" token="@token"></drupal-html-response-attachment-placeholder>', [
'@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;
}
}
......
......@@ -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 <head>.
* - scripts: HTML necessary to load JavaScript files and settings in <head>.
* - scripts_bottom: HTML necessary to load JavaScript files before closing
* <body> 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 @@
<!DOCTYPE html>
<html{{ html_attributes }}>
<head>
{{ head }}
<head-placeholder token="{{ placeholder_token|raw }}" />
<title>{{ head_title|safe_join(' | ') }}</title>
{{ styles }}
{{ scripts }}
<css-placeholder token="{{ placeholder_token|raw }}" />
<js-placeholder token="{{ placeholder_token|raw }}" />
</head>
<body{{ attributes }}>
<a href="#main-content" class="visually-hidden focusable">
......@@ -45,6 +40,6 @@
{{ page_top }}
{{ page }}
{{ page_bottom }}
{{ scripts_bottom }}
<js-bottom-placeholder token="{{ placeholder_token|raw }}" />
</body>
</html>
......@@ -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 <head>.
* - scripts: HTML necessary to load JavaScript files and settings in <head>.
* - scripts_bottom: HTML necessary to load JavaScript files before closing
* <body> 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 @@
<!DOCTYPE html>
<html{{ html_attributes }}>
<head>
{{ head }}
<head-placeholder token="{{ placeholder_token|raw }}" />
<title>{{ head_title|safe_join(' | ') }}</title>
{{ styles }}
{{ scripts }}
<css-placeholder token="{{ placeholder_token|raw }}" />
<js-placeholder token="{{ placeholder_token|raw }}" />
</head>
<body{{ attributes.addClass(body_classes) }}>
<a href="#main-content" class="visually-hidden focusable skip-link">
......@@ -51,6 +46,6 @@
{{ page_top }}
{{ page }}
{{ page_bottom }}
{{ scripts_bottom }}
<js-bottom-placeholder token="{{ placeholder_token|raw }}" />
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment