Issue #2538950 by alexpott, dawehner, stefan.r: Replace SafeMarkup::format() in template_preprocess_html with placeholders in the template

8.0.x
Nathaniel Catchpole 2015-09-08 15:42:02 +01:00
parent 4c7b4763de
commit 6b46410712
3 changed files with 20 additions and 34 deletions

View File

@ -1269,19 +1269,15 @@ function template_preprocess_html(&$variables) {
// Create placeholder strings for these keys. // Create placeholder strings for these keys.
// @see \Drupal\Core\Render\HtmlResponseSubscriber // @see \Drupal\Core\Render\HtmlResponseSubscriber
$types = [ $types = [
'styles', 'styles' => 'css',
'scripts', 'scripts' => 'js',
'scripts_bottom', 'scripts_bottom' => 'js-bottom',
'head', 'head' => 'head',
]; ];
$token = Crypt::randomBytesBase64(55); $variables['placeholder_token'] = Crypt::randomBytesBase64(55);
foreach ($types as $type) { foreach ($types as $type => $placeholder_name) {
$placeholder = SafeMarkup::format('<drupal-html-response-attachment-placeholder type="@type" token="@token"></drupal-html-response-attachment-placeholder>', [ $placeholder = '<' . $placeholder_name . '-placeholder token="' . $variables['placeholder_token'] . '" />';
'@type' => $type, $variables['#attached']['html_response_attachment_placeholders'][$type] = $placeholder;
'@token' => $token,
]);
$variables[$type]['#markup'] = $placeholder;
$variables[$type]['#attached']['html_response_attachment_placeholders'][$type] = $placeholder;
} }
} }

View File

@ -7,9 +7,6 @@
* - logged_in: A flag indicating if user is logged in. * - logged_in: A flag indicating if user is logged in.
* - root_path: The root path of the current page (e.g., node, admin, user). * - 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. * - 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. * - head_title: List of text elements that make up the head_title variable.
* May contain or more of the following: * May contain or more of the following:
* - title: The title of the page. * - title: The title of the page.
@ -19,11 +16,9 @@
* - page: The rendered page markup. * - page: The rendered page markup.
* - page_bottom: Closing rendered markup. This variable should be printed after * - page_bottom: Closing rendered markup. This variable should be printed after
* 'page'. * '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. * - 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() * @see template_preprocess_html()
* *
@ -33,10 +28,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html{{ html_attributes }}> <html{{ html_attributes }}>
<head> <head>
{{ head }} <head-placeholder token="{{ placeholder_token|raw }}" />
<title>{{ head_title|safe_join(' | ') }}</title> <title>{{ head_title|safe_join(' | ') }}</title>
{{ styles }} <css-placeholder token="{{ placeholder_token|raw }}" />
{{ scripts }} <js-placeholder token="{{ placeholder_token|raw }}" />
</head> </head>
<body{{ attributes }}> <body{{ attributes }}>
<a href="#main-content" class="visually-hidden focusable"> <a href="#main-content" class="visually-hidden focusable">
@ -45,6 +40,6 @@
{{ page_top }} {{ page_top }}
{{ page }} {{ page }}
{{ page_bottom }} {{ page_bottom }}
{{ scripts_bottom }} <js-bottom-placeholder token="{{ placeholder_token|raw }}" />
</body> </body>
</html> </html>

View File

@ -7,9 +7,6 @@
* - logged_in: A flag indicating if user is logged in. * - logged_in: A flag indicating if user is logged in.
* - root_path: The root path of the current page (e.g., node, admin, user). * - 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. * - 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. * - head_title: List of text elements that make up the head_title variable.
* May contain or more of the following: * May contain or more of the following:
* - title: The title of the page. * - title: The title of the page.
@ -19,11 +16,9 @@
* - page: The rendered page markup. * - page: The rendered page markup.
* - page_bottom: Closing rendered markup. This variable should be printed after * - page_bottom: Closing rendered markup. This variable should be printed after
* 'page'. * '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. * - 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() * @see template_preprocess_html()
*/ */
@ -39,10 +34,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html{{ html_attributes }}> <html{{ html_attributes }}>
<head> <head>
{{ head }} <head-placeholder token="{{ placeholder_token|raw }}" />
<title>{{ head_title|safe_join(' | ') }}</title> <title>{{ head_title|safe_join(' | ') }}</title>
{{ styles }} <css-placeholder token="{{ placeholder_token|raw }}" />
{{ scripts }} <js-placeholder token="{{ placeholder_token|raw }}" />
</head> </head>
<body{{ attributes.addClass(body_classes) }}> <body{{ attributes.addClass(body_classes) }}>
<a href="#main-content" class="visually-hidden focusable skip-link"> <a href="#main-content" class="visually-hidden focusable skip-link">
@ -51,6 +46,6 @@
{{ page_top }} {{ page_top }}
{{ page }} {{ page }}
{{ page_bottom }} {{ page_bottom }}
{{ scripts_bottom }} <js-bottom-placeholder token="{{ placeholder_token|raw }}" />
</body> </body>
</html> </html>