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()) {
* @see template_process()
*/
function theme($hook, $variables = array()) {
static $default_attributes;
// 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
// request properly. See also _theme_load_registry().
......@@ -1157,6 +1158,20 @@ function theme($hook, $variables = array()) {
template_preprocess($default_template_variables, $hook);
$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.
$template_file = $info['template'] . $extension;
......@@ -2620,7 +2635,6 @@ function _theme_table_cell($cell, $header = FALSE) {
*/
function template_preprocess(&$variables, $hook) {
global $user;
static $count = array(), $default_attributes;
// Tell all templates where they are located.
$variables['directory'] = path_to_theme();
......@@ -2636,13 +2650,10 @@ function template_preprocess(&$variables, $hook) {
if (!isset($default_variables)) {
$default_variables = _template_preprocess_default_variables();
}
if (!isset($default_attributes)) {
$default_attributes = new Attribute(array('class' => array()));
}
$variables += $default_variables + array(
'attributes' => clone $default_attributes,
'title_attributes' => clone $default_attributes,
'content_attributes' => clone $default_attributes,
'attributes' => array(),
'title_attributes' => array(),
'content_attributes' => array(),
);
// Initialize html class attribute for the current hook.
......
......@@ -159,7 +159,7 @@ protected function renderTests() {
$expected = array();
$expected[] = ' <div id="block-test-block" class="block block-block-test">';
$expected[] = '';
$expected[] = ' <h2 class="">Powered by Bananas</h2>';
$expected[] = ' <h2>Powered by Bananas</h2>';
$expected[] = ' ';
$expected[] = ' <div class="content">';
$expected[] = ' </div>';
......
......@@ -481,7 +481,7 @@ function views_preprocess_html(&$variables) {
// the "contextual-region" class from the <body> tag here and add
// JavaScript that will insert it back in the correct place.
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) {
unset($variables['attributes']['class'][$key]);
// 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