commit 1f29f609a63a9526009c525011ed7653932f6ac9 Author: Joel Pittet Date: Tue Feb 25 13:43:57 2014 -0800 fixes and remove premature optimise and missing attribute use diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 1fb7f06..2ed3ad0 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -524,7 +524,6 @@ function drupal_find_base_themes($themes, $key) { * @see template_preprocess() */ 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 \Drupal\Core\Theme\Registry::get(). @@ -725,18 +724,9 @@ function _theme($hook, $variables = array()) { template_preprocess($default_template_variables, $hook, $info); $variables += $default_template_variables; } - if (!isset($default_attributes)) { - $default_attributes = new Attribute(); - } if (isset($variables['attributes']) && !($variables['attributes'] instanceof Attribute)) { - if ($variables['attributes']) { - $variables['attributes'] = new Attribute($variables['attributes']); - } - else { - // Create empty attributes. - $variables['attributes'] = clone $default_attributes; - } + $variables['attributes'] = new Attribute($variables['attributes']); } // Render the output using the template file. diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 7e6332a..0011b41 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -492,14 +492,9 @@ function template_preprocess_block(&$variables) { $variables['attributes']['id'] = drupal_html_id('block-' . $id); } - static $default_attributes; - if (!isset($default_attributes)) { - $default_attributes = new Attribute; - } - // For best performance, we only instantiate Attribute objects when needed. - $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : clone $default_attributes; - $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : clone $default_attributes; + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : NULL; + $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : NULL; } /** diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 2df98e1..12b0a75 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1518,15 +1518,10 @@ function template_preprocess_comment(&$variables) { $variables['attributes']['data-comment-user-id'] = $comment->getOwnerId(); $variables['content_attributes']['class'][] = 'content'; + $variables['content_attributes'] = new Attribute($variables['content_attributes']); - static $default_attributes; - if (!isset($default_attributes)) { - $default_attributes = new Attribute; - } - - // For best performance, we only instantiate Attribute objects when needed. - $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : clone $default_attributes; - $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : clone $default_attributes; + $variables['title_attributes'] = isset($variables['title_attributes']) ? $variables['title_attributes'] : array(); + $variables['title_attributes'] = new Attribute($variables['title_attributes']); } /** diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 393adad..168d9d3 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -540,15 +540,9 @@ function template_preprocess_field(&$variables, $hook) { $variables['attributes']['class'][] = 'clearfix'; } - static $default_attributes; - if (!isset($default_attributes)) { - $default_attributes = new Attribute; - } - - // For best performance, we only instantiate Attribute objects when needed. - $variables['attributes'] = isset($variables['attributes']) ? new Attribute($variables['attributes']) : clone $default_attributes; - $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : clone $default_attributes; - $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : clone $default_attributes; + $variables['attributes'] = new Attribute($variables['attributes']); + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute(); + $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : new Attribute(); // Modules (e.g., rdf.module) can add field item attributes (to // $item->_attributes) within hook_entity_prepare_view(). Some field @@ -558,7 +552,7 @@ function template_preprocess_field(&$variables, $hook) { // formatters leave them within $element['#items'][$delta]['_attributes'] to // be rendered on the item wrappers provided by theme_field(). foreach ($variables['items'] as $delta => $item) { - $variables['item_attributes'][$delta] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone $default_attributes; + $variables['item_attributes'][$delta] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : new Attribute(); } } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index f5a2c13..1a02b4c 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -713,16 +713,8 @@ function template_preprocess_node(&$variables) { $variables['attributes']['class'][] = 'preview'; } $variables['content_attributes']['class'][] = 'content'; - - static $default_attributes; - if (!isset($default_attributes)) { - $default_attributes = new Attribute; - } - - // For best performance, we only instantiate Attribute objects when needed. - $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : clone $default_attributes; - $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : clone $default_attributes; - + $variables['content_attributes'] = new Attribute($variables['content_attributes']); + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute(); } /** diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index 432dbb1..671e63a 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -6,6 +6,7 @@ */ use Drupal\Core\Language\Language; +use Drupal\Core\Template\Attribute; /** * Implements hook_theme_suggestions_HOOK(). @@ -60,13 +61,7 @@ function template_preprocess_search_result(&$variables) { $variables['info_split'] = $info; $variables['info'] = implode(' - ', $info); - static $default_attributes; - if (!isset($default_attributes)) { - $default_attributes = new Attribute; - } - - // For best performance, we only instantiate Attribute objects when needed. - $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : clone $default_attributes; - $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : clone $default_attributes; + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute(); + $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : new Attribute(); }