diff --git a/core/includes/theme.inc b/core/includes/theme.inc index a6d9362..34c539a 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -760,20 +760,6 @@ function theme($hook, $variables = array()) { template_preprocess($default_template_variables, $hook, $info); $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; @@ -2004,6 +1990,7 @@ function template_preprocess_feed_icon(&$variables) { $variables['attributes']['class'] = array('feed-icon'); // Stripping tags because that's what l() used to do. $variables['attributes']['title'] = strip_tags($text); + $variables['attributes'] = new Attribute($variables['attributes']); } /** @@ -2215,6 +2202,8 @@ function template_preprocess_html(&$variables) { } } + $variables['attributes'] = new Attribute($variables['attributes']); + // Initializes attributes which are specific to the html and body elements. $variables['html_attributes'] = new Attribute; @@ -2611,6 +2600,8 @@ function template_preprocess_maintenance_page(&$variables) { $variables['attributes']['class'][] = 'sidebar-' . $variables['layout']; } + $variables['attributes'] = new Attribute($variables['attributes']); + $variables['head'] = drupal_get_html_head(); // While this code is used in the installer, the language module may not be @@ -2675,6 +2666,8 @@ function template_preprocess_region(&$variables) { $variables['attributes']['class'][] = 'region'; $variables['attributes']['class'][] = drupal_html_class('region-' . $variables['region']); + + $variables['attributes'] = new Attribute($variables['attributes']); } /** diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 726f228..de20f9b 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -417,4 +417,5 @@ 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/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index 137d987..91894aa 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -219,4 +219,5 @@ function template_preprocess_aggregator_feed_source(&$variables) { } $variables['attributes']['class'][] = 'feed-source'; + $variables['attributes'] = new Attribute($variables['attributes']); } diff --git a/core/modules/block/block.module b/core/modules/block/block.module index e1bc631..e467a09 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -8,6 +8,7 @@ use Drupal\block\BlockInterface; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Template\Attribute; use Symfony\Cmf\Component\Routing\RouteObjectInterface; /** @@ -520,6 +521,9 @@ function template_preprocess_block(&$variables) { // them through to the content's #theme function/template. This allows the // content to not require a function/template at all, or if it does use one, // to not require it to output an extra wrapping element. + if(!isset($variables['content_attributes'])) { + $variables['content_attributes'] = array(); + } if (isset($variables['content']['#attributes'])) { $variables['content_attributes'] = NestedArray::mergeDeep($variables['content_attributes'], $variables['content']['#attributes']); unset($variables['content']['#attributes']); @@ -527,11 +531,14 @@ 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']); } /** diff --git a/core/modules/book/book.module b/core/modules/book/book.module index c9fccf5..a806cb3 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -648,6 +648,7 @@ 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 fa38bfb..aea23e4 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityChangedInterface; +use Drupal\Core\Template\Attribute; use Drupal\comment\CommentInterface; use Drupal\comment\Entity\Comment; use Drupal\entity\Entity\EntityDisplay; @@ -1355,6 +1356,7 @@ function comment_preprocess_block(&$variables) { if ($variables['configuration']['module'] == 'comment') { $variables['attributes']['role'] = 'navigation'; } + $variables['attributes'] = new Attribute($variables['attributes']); } /** @@ -1507,8 +1509,11 @@ 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']); + } /** @@ -1584,6 +1589,7 @@ function template_preprocess_comment_wrapper(&$variables) { // Add a comment wrapper class. $variables['attributes']['class'][] = 'comment-wrapper'; + $variables['attributes'] = new Attribute($variables['attributes']); // Create separate variables for the comments and comment form. $variables['comments'] = $variables['content']['comments']; diff --git a/core/modules/contextual/contextual.module b/core/modules/contextual/contextual.module index 130ba4c..54eda5f 100644 --- a/core/modules/contextual/contextual.module +++ b/core/modules/contextual/contextual.module @@ -201,6 +201,7 @@ 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/datetime/datetime.module b/core/modules/datetime/datetime.module index da33989..8afa90c 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -242,7 +242,6 @@ function datetime_date_default_time($date) { function template_preprocess_datetime_form(&$variables) { $element = $variables['element']; - $variables['attributes'] = array(); if (isset($element['#id'])) { $variables['attributes']['id'] = $element['#id']; } @@ -251,6 +250,7 @@ function template_preprocess_datetime_form(&$variables) { } $variables['attributes']['class'][] = 'container-inline'; + $variables['attributes'] = new Attribute($variables['attributes']); $variables['content'] = $element; } diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 0d56a0a..e463269 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -675,9 +675,9 @@ function template_preprocess_field(&$variables, $hook) { // 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'] = 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'] = clone $default_attributes; + $variables['title_attributes'] = clone($default_attributes); + $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 diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index e860181..3ef95f8 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -575,6 +575,7 @@ 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 a860f3f..855fbba 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -703,7 +703,9 @@ 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']); } /** diff --git a/core/modules/overlay/overlay.module b/core/modules/overlay/overlay.module index 81279c1..17649b1 100644 --- a/core/modules/overlay/overlay.module +++ b/core/modules/overlay/overlay.module @@ -5,6 +5,7 @@ * Displays the Drupal administration interface in an overlay. */ +use Drupal\Core\Template\Attribute; use Drupal\Core\Template\RenderWrapper; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response; @@ -381,11 +382,14 @@ function template_preprocess_overlay(&$variables) { // Add attributes for the overlay container. $variables['attributes']['id'] = 'overlay'; $variables['attributes']['class'][] = 'overlay'; + $variables['attributes'] = new Attributes($variables['attributes']); // Add attributes for the overlay title. $variables['title_attributes']['id'] = 'overlay-title'; + $variables['title_attributes'] = new Attributes($variables['title_attributes']); // Add attributes for the overlay content. $variables['content_attributes']['id'] = 'overlay-content'; $variables['content_attributes']['class'][] = 'clearfix'; + $variables['content_attributes'] = new Attributes($variables['content_attributes']); } /** diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index cfa935b..f89a51c 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -275,6 +275,7 @@ function rdf_preprocess_node(&$variables) { $bundle_mapping = $mapping->getPreparedBundleMapping('node', $bundle); $variables['attributes']['about'] = empty($variables['node_url']) ? NULL: $variables['node_url']; $variables['attributes']['typeof'] = empty($bundle_mapping['types']) ? NULL : $bundle_mapping['types']; + $variables['attributes'] = new Attribute($variables['attributes']); // Adds RDFa markup for the node title as metadata because wrapping the title // with markup is not reliable and the title output is different depdending on @@ -342,6 +343,7 @@ function rdf_preprocess_user(&$variables) { if (!empty($bundle_mapping['types'])) { $variables['attributes']['typeof'] = $bundle_mapping['types']; $variables['attributes']['about'] = url($uri['path'], $uri['options']); + $variables['attributes'] = new Attribute($variables['attributes']); } // If we are on the user account page, add the relationship between the // sioc:UserAccount and the foaf:Person who holds the account. @@ -419,6 +421,7 @@ function rdf_preprocess_username(&$variables) { } else { $variables['attributes'] = array_merge_recursive($variables['attributes'], $attributes); + $variables['attributes'] = new Attribute($variables['attributes']); } } @@ -474,6 +477,7 @@ 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 @@ -540,6 +544,7 @@ 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 56e6859..d417a77 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Template\Attribute; use Drupal\Component\Utility\Unicode; use Drupal\search\SearchExpression; use Drupal\search\Plugin\SearchInterface; @@ -142,7 +143,9 @@ 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 023a825..a9c6326 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; use Symfony\Component\HttpFoundation\RedirectResponse; /** @@ -67,7 +68,9 @@ 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(); diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 2977253..c931c00 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -10,6 +10,7 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; use Drupal\Component\Utility\Crypt; +use Drupal\Core\Template\Attribute; /** * Menu callback; process one time login link and redirects to the user page on success. @@ -118,6 +119,7 @@ function template_preprocess_user(&$variables) { // Set up attributes. $variables['attributes']['class'][] = 'profile'; + $variables['attributes'] = new Attribute($variables['attributes']); } /** diff --git a/core/modules/views/views.module b/core/modules/views/views.module index ff1bdc4..ff67981 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -424,7 +424,7 @@ function views_preprocess_html(&$variables) { // remove the "contextual-region" class from the tag here and add // JavaScript that will insert it back in the correct place. if (!empty($variables['page']['#views_contextual_links'])) { - $key = array_search('contextual-region', $variables['attributes']['class']); + $key = array_search('contextual-region', $variables['attributes']['class']->value()); if ($key !== FALSE) { unset($variables['attributes']['class'][$key]); $variables['attributes']['data-views-page-contextual-id'] = $variables['title_suffix']['contextual_links']['#id']; diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 6c6cd0a..9a9d8fc 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -151,6 +151,8 @@ function template_preprocess_views_view(&$variables) { } $variables['rows'] = $form; } + + $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 a13467e..5f4e1f7 100644 --- a/core/modules/views_ui/views_ui.theme.inc +++ b/core/modules/views_ui/views_ui.theme.inc @@ -50,6 +50,8 @@ function template_preprocess_views_ui_display_tab_setting(&$variables) { if ($variables['description'] && $variables['description_separator']) { $variables['description'] .= t(':'); } + + $variables['attributes'] = new Attribute($variables['attributes']); } /** diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme index e334125..9e3ea11 100644 --- a/core/themes/bartik/bartik.theme +++ b/core/themes/bartik/bartik.theme @@ -5,6 +5,7 @@ * Functions to support theming in the Bartik theme. */ +use Drupal\Core\Template\Attribute; use Drupal\Core\Template\RenderWrapper; /** @@ -45,6 +46,7 @@ function bartik_preprocess_html(&$variables) { || !empty($variables['page']['footer_fourthcolumn'])) { $variables['attributes']['class'][] = 'footer-columns'; } + $variables['attributes'] = new Attribute($variables['attributes']); } /** @@ -191,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; }