Commit c33191b6 authored by catch's avatar catch

Issue #1982024 by Cottser, Fabianx: Lazy-load Attribute objects later in the...

Issue #1982024 by Cottser, Fabianx: Lazy-load Attribute objects later in the rendering process only if needed.
parent 50ae3296
...@@ -961,6 +961,7 @@ function drupal_find_base_themes($themes, $key, $used_keys = array()) { ...@@ -961,6 +961,7 @@ function drupal_find_base_themes($themes, $key, $used_keys = array()) {
* @see template_process() * @see template_process()
*/ */
function theme($hook, $variables = array()) { function theme($hook, $variables = array()) {
static $default_attributes;
// If called before all modules are loaded, we do not necessarily have a full // If called before all modules are loaded, we do not necessarily have a full
// theme registry to work with, and therefore cannot process the theme // theme registry to work with, and therefore cannot process the theme
// request properly. See also _theme_load_registry(). // request properly. See also _theme_load_registry().
...@@ -1157,6 +1158,20 @@ function theme($hook, $variables = array()) { ...@@ -1157,6 +1158,20 @@ function theme($hook, $variables = array()) {
template_preprocess($default_template_variables, $hook); template_preprocess($default_template_variables, $hook);
$variables += $default_template_variables; $variables += $default_template_variables;
} }
if (!isset($default_attributes)) {
$default_attributes = new Attribute();
}
foreach (array('attributes', 'title_attributes', 'content_attributes') as $key) {
if (isset($variables[$key]) && !($variables[$key] instanceof Attribute)) {
if ($variables[$key]) {
$variables[$key] = new Attribute($variables[$key]);
}
else {
// Create empty attributes.
$variables[$key] = clone $default_attributes;
}
}
}
// Render the output using the template file. // Render the output using the template file.
$template_file = $info['template'] . $extension; $template_file = $info['template'] . $extension;
...@@ -2620,7 +2635,6 @@ function _theme_table_cell($cell, $header = FALSE) { ...@@ -2620,7 +2635,6 @@ function _theme_table_cell($cell, $header = FALSE) {
*/ */
function template_preprocess(&$variables, $hook) { function template_preprocess(&$variables, $hook) {
global $user; global $user;
static $count = array(), $default_attributes;
// Tell all templates where they are located. // Tell all templates where they are located.
$variables['directory'] = path_to_theme(); $variables['directory'] = path_to_theme();
...@@ -2636,13 +2650,10 @@ function template_preprocess(&$variables, $hook) { ...@@ -2636,13 +2650,10 @@ function template_preprocess(&$variables, $hook) {
if (!isset($default_variables)) { if (!isset($default_variables)) {
$default_variables = _template_preprocess_default_variables(); $default_variables = _template_preprocess_default_variables();
} }
if (!isset($default_attributes)) {
$default_attributes = new Attribute(array('class' => array()));
}
$variables += $default_variables + array( $variables += $default_variables + array(
'attributes' => clone $default_attributes, 'attributes' => array(),
'title_attributes' => clone $default_attributes, 'title_attributes' => array(),
'content_attributes' => clone $default_attributes, 'content_attributes' => array(),
); );
// Initialize html class attribute for the current hook. // Initialize html class attribute for the current hook.
......
...@@ -159,7 +159,7 @@ protected function renderTests() { ...@@ -159,7 +159,7 @@ protected function renderTests() {
$expected = array(); $expected = array();
$expected[] = ' <div id="block-test-block" class="block block-block-test">'; $expected[] = ' <div id="block-test-block" class="block block-block-test">';
$expected[] = ''; $expected[] = '';
$expected[] = ' <h2 class="">Powered by Bananas</h2>'; $expected[] = ' <h2>Powered by Bananas</h2>';
$expected[] = ' '; $expected[] = ' ';
$expected[] = ' <div class="content">'; $expected[] = ' <div class="content">';
$expected[] = ' </div>'; $expected[] = ' </div>';
......
...@@ -481,7 +481,7 @@ function views_preprocess_html(&$variables) { ...@@ -481,7 +481,7 @@ function views_preprocess_html(&$variables) {
// the "contextual-region" class from the <body> tag here and add // the "contextual-region" class from the <body> tag here and add
// JavaScript that will insert it back in the correct place. // JavaScript that will insert it back in the correct place.
if (!empty($variables['page']['#views_contextual_links_info'])) { if (!empty($variables['page']['#views_contextual_links_info'])) {
$key = array_search('contextual-region', $variables['attributes']['class']->value()); $key = array_search('contextual-region', $variables['attributes']['class']);
if ($key !== FALSE) { if ($key !== FALSE) {
unset($variables['attributes']['class'][$key]); unset($variables['attributes']['class'][$key]);
// Add the JavaScript, with a group and weight such that it will run // Add the JavaScript, with a group and weight such that it will run
......
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