commit c1b166795816424dab565e7e5ac53f67f80a42d8 Author: Joel Pittet Date: Wed Jan 29 00:31:12 2014 -0800 touchups diff --git a/core/includes/theme.inc b/core/includes/theme.inc index c89b979..f917504 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2023,8 +2023,6 @@ function _template_preprocess_default_variables() { // Variables that don't depend on a database connection. $variables = array( 'attributes' => array(), - 'title_attributes' => array(), - 'content_attributes' => array(), 'title_prefix' => array(), 'title_suffix' => array(), 'db_is_active' => !defined('MAINTENANCE_MODE'), diff --git a/core/lib/Drupal/Core/Template/Attribute.php b/core/lib/Drupal/Core/Template/Attribute.php index 473b31a..1ebdd9f 100644 --- a/core/lib/Drupal/Core/Template/Attribute.php +++ b/core/lib/Drupal/Core/Template/Attribute.php @@ -83,6 +83,9 @@ protected function createAttributeValue($name, $value) { if (is_array($value)) { $value = new AttributeArray($name, $value); } + elseif ($name == 'class') { + $value = new AttributeArray($name, array($value)); + } elseif (is_bool($value)) { $value = new AttributeBoolean($name, $value); } diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index ef38caf..ef155dc 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -318,5 +318,4 @@ function aggregator_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'aggregator') { $variables['attributes']['role'] = 'complementary'; } - $variables['attributes'] = new Attribute($variables['attributes']); } diff --git a/core/modules/block/block.module b/core/modules/block/block.module index d7c4ae0..c25ee65 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -503,14 +503,21 @@ function template_preprocess_block(&$variables) { // Add default class for block content. $variables['content_attributes']['class'][] = 'content'; - $variables['content_attributes'] = new Attribute($variables['content_attributes']); // Create a valid HTML ID and make sure it is unique. if ($id = $variables['elements']['#block']->id()) { $variables['attributes']['id'] = drupal_html_id('block-' . $id); } - $variables['title_attributes'] = ''; - $variables['attributes'] = new Attribute($variables['attributes']); + + 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; } /** diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 89483be..0457488 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -598,7 +598,6 @@ function book_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'book') { $variables['attributes']['role'] = 'navigation'; } - $variables['attributes'] = new Attribute($variables['attributes']); } /** diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 43de7c2..6bef9db 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -1309,7 +1309,6 @@ function comment_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'comment') { $variables['attributes']['role'] = 'navigation'; } - $variables['attributes'] = new Attribute($variables['attributes']); } /** @@ -1459,11 +1458,18 @@ function template_preprocess_comment(&$variables) { // Add comment author user ID. Necessary for the comment-by-viewer library. $variables['attributes']['data-comment-user-id'] = $comment->uid->value; - $variables['attributes'] = new Attribute($variables['attributes']); $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['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; } /** diff --git a/core/modules/contextual/contextual.module b/core/modules/contextual/contextual.module index ecb19b4..3fd2cb9 100644 --- a/core/modules/contextual/contextual.module +++ b/core/modules/contextual/contextual.module @@ -196,7 +196,6 @@ function contextual_preprocess(&$variables, $hook, $info) { if (isset($element) && is_array($element) && !empty($element['#contextual_links'])) { // Mark this element as potentially having contextual links attached to it. $variables['attributes']['class'][] = 'contextual-region'; - $variables['attributes'] = new Attribute($variables['attributes']); // Renders a contextual links placeholder unconditionally, thus not breaking // the render cache. Although the empty placeholder is rendered for all diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 5200fc7..0c521f5 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -556,16 +556,11 @@ function template_preprocess_field(&$variables, $hook) { if (!isset($default_attributes)) { $default_attributes = new Attribute; } - // The default theme implementation for fields is a function. - // template_preprocess() (which initializes the attributes, title_attributes, - // and content_attributes arrays) does not run for theme function - // implementations. Additionally, Attribute objects for the three variables - // below only get instantiated for template file implementations, and we need - // Attribute objects for printing in both theme functions and template files. + // For best performance, we only instantiate Attribute objects when needed. - $variables['attributes'] = clone $default_attributes; - $variables['title_attributes'] = clone($default_attributes); - $variables['content_attributes'] = clone($default_attributes); + $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; // Modules (e.g., rdf.module) can add field item attributes (to // $item->_attributes) within hook_entity_prepare_view(). Some field @@ -575,7 +570,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) : clone $default_attributes; } } diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index 8c495b9b..538d6b3 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -574,7 +574,6 @@ function forum_block_view_pre_render($elements) { function forum_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'forum') { $variables['attributes']['role'] = 'navigation'; - $variables['attributes'] = new Attribute($variables['attributes']); } } diff --git a/core/modules/node/node.module b/core/modules/node/node.module index c12507f..eda70ec 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -702,9 +702,18 @@ function template_preprocess_node(&$variables) { if (isset($variables['preview'])) { $variables['attributes']['class'][] = 'preview'; } - $variables['attributes'] = new Attribute($variables['attributes']); $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['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; + } /** diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index e229e39..d2fa4ba 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -478,7 +478,6 @@ function rdf_preprocess_comment(&$variables) { // is a literal. $variables['title_attributes']['property'] = $title_mapping['properties']; $variables['title_attributes']['datatype'] = ''; - $variables['title_attributes'] = new Attribute($variables['title_attributes']); } // Annotates the parent relationship between the current comment and the node @@ -545,7 +544,6 @@ function rdf_preprocess_image(&$variables) { // to get 'foaf:Image' because image does not have its own entity type or // bundle. $variables['attributes']['typeof'] = array('foaf:Image'); - $variables['attributes'] = new Attribute($variables['attributes']); } /** diff --git a/core/modules/search/search.module b/core/modules/search/search.module index a89c725..25f9825 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -5,7 +5,6 @@ * Enables site-wide keyword searching. */ -use Drupal\Core\Template\Attribute; use Drupal\Component\Utility\Unicode; /** @@ -140,9 +139,7 @@ function search_permission() { function search_preprocess_block(&$variables) { if ($variables['plugin_id'] == 'search_form_block') { $variables['attributes']['role'] = 'search'; - $variables['attributes'] = new Attribute($variables['attributes']); $variables['content_attributes']['class'][] = 'container-inline'; - $variables['content_attributes'] = new Attribute($variables['content_attributes']); } } diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index a9c6326..b1ef5d9 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -68,9 +68,7 @@ function template_preprocess_search_result(&$variables) { $variables['title'] = check_plain($result['title']); if (isset($result['language']) && $result['language'] != $language_interface->id && $result['language'] != Language::LANGCODE_NOT_SPECIFIED) { $variables['title_attributes']['lang'] = $result['language']; - $variables['title_attributes'] = new Attribute($variables['title_attributes']); $variables['content_attributes']['lang'] = $result['language']; - $variables['content_attributes'] = new Attribute($variables['content_attributes']); } $info = array(); @@ -91,5 +89,15 @@ function template_preprocess_search_result(&$variables) { // Provide separated and grouped meta information.. $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['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; } diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index f35d4ae..8ab4736 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -221,7 +221,7 @@ function template_preprocess_toolbar(&$variables) { $element = $variables['element']; // Prepare the toolbar attributes. - $variables['attributes'] = $element['#attributes']; + $variables['attributes'] = new Attribute($element['#attributes']); $variables['toolbar_attributes'] = new Attribute($element['#bar']['#attributes']); $variables['toolbar_heading'] = $element['#bar']['#heading']; diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 9a9d8fc..48dd2c9 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -752,6 +752,8 @@ function template_preprocess_views_view_table(&$variables) { // This is needed to target tables constructed by this function. $variables['attributes']['class'][] = 'responsive-enabled'; } + + $variables['attributes'] = new Attribute($variables['#attributes']); } /** @@ -875,6 +877,7 @@ function template_preprocess_views_view_grid(&$variables) { // Add items to the variables array. $variables['items'] = $items; + $variables['attributes'] = new Attribute($variables['#attributes']); } /** @@ -921,6 +924,7 @@ function template_preprocess_views_view_unformatted(&$variables) { } $variables['rows'][$id]['attributes'] = new Attribute($variables['rows'][$id]['attributes']); } + $variables['attributes'] = new Attribute($variables['#attributes']); } /** diff --git a/core/modules/views_ui/views_ui.theme.inc b/core/modules/views_ui/views_ui.theme.inc index fa4f563..776e49f 100644 --- a/core/modules/views_ui/views_ui.theme.inc +++ b/core/modules/views_ui/views_ui.theme.inc @@ -76,6 +76,8 @@ function template_preprocess_views_ui_display_tab_bucket(&$variables) { $variables['content'] = $element['#children']; $variables['title'] = $element['#title']; $variables['actions'] = !empty($element['#actions']) ? $element['#actions'] : array(); + + $variables['attributes'] = new Attribute($variables['attributes']); } /** diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme index 5950c60..ab4683c 100644 --- a/core/themes/bartik/bartik.theme +++ b/core/themes/bartik/bartik.theme @@ -5,7 +5,6 @@ * Functions to support theming in the Bartik theme. */ -use Drupal\Core\Template\Attribute; use Drupal\Core\Template\RenderWrapper; /** @@ -92,8 +91,6 @@ function bartik_preprocess_page(&$variables) { // Make sure the shortcut link is the first item in title_suffix. $variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100; } - - $variables['attributes'] = new Attribute($variables['attributes']); } /** @@ -196,7 +193,7 @@ function bartik_field__taxonomy_term_reference($variables) { // Render the top-level DIV. $variables['attributes']['class'][] = 'clearfix'; - $output = '
' . $output . '
'; + $output = '
' . $output . '
'; return $output; }