diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 34dbdc2..b454e71 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1298,8 +1298,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'), @@ -1706,9 +1704,13 @@ function template_preprocess_field(&$variables, $hook) { // the element of a field item being rendered as a link). Other field // formatters leave them within $element['#items'][$delta]['_attributes'] to // be rendered on the item wrappers provided by field.html.twig. - $variables['items'][$delta]['attributes'] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes); - $delta++; + 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['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/lib/Drupal/Core/Theme/ThemeManager.php b/core/lib/Drupal/Core/Theme/ThemeManager.php index a100374..f86565b 100644 --- a/core/lib/Drupal/Core/Theme/ThemeManager.php +++ b/core/lib/Drupal/Core/Theme/ThemeManager.php @@ -345,15 +345,13 @@ protected function theme($hook, $variables = array()) { 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; - } + 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; } } diff --git a/core/modules/block/block.module b/core/modules/block/block.module index 6506ab2..41bbef7 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -11,6 +11,7 @@ use Drupal\language\ConfigurableLanguageInterface; use Drupal\system\Entity\Menu; use Drupal\block\Entity\Block; +use Drupal\Core\Template\Attribute; /** * Implements hook_help(). @@ -257,6 +258,10 @@ function template_preprocess_block(&$variables) { $variables['attributes']['aria-describedby'] = $variables['title_attributes']['id']; } + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute(); + + // Add default class for block content. + $variables['content_attributes'] = new Attribute($variables['content_attributes']); } /** diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 0ee6f4c..c0dc016 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -24,6 +24,7 @@ use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Render\Element; +use Drupal\Core\Template\Attribute; use Drupal\Core\Url; use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\FieldConfigInterface; @@ -793,6 +794,9 @@ function template_preprocess_comment(&$variables) { // Add comment author user ID. Necessary for the comment-by-viewer library. $variables['attributes']['data-comment-user-id'] = $comment->getOwnerId(); + $variables['content_attributes']['class'][] = 'content'; + $variables['content_attributes'] = new Attribute($variables['content_attributes']); + $variables['title_attributes'] = isset($variables['title_attributes']) ? new Attribute($variables['title_attributes']) : new Attribute(); } /** @@ -817,7 +821,6 @@ function comment_preprocess_field(&$variables) { // Adjust a comment field's attributes. $variables['attributes']['class'][] = 'comment-wrapper'; - $variables['title_attributes']['class'][] = 'title'; // Append additional attributes (eg. RDFa) from the first field item. $variables['attributes'] += $variables['items'][0]['attributes']->storage(); @@ -825,7 +828,8 @@ function comment_preprocess_field(&$variables) { // Create separate variables for the comments and comment form. $variables['comments'] = $element[0]['comments']; $variables['comment_form'] = $element[0]['comment_form']; - $variables['content_attributes']['class'] = array('title', 'comment-form__title'); + $variables['title_attributes']->addClass('title'); + $variables['content_attributes']->addClass(array('title', 'comment-form__title')); } } diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index 4c84c84..2c45678 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -7,6 +7,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\Template\Attribute; /** * Implements hook_theme_suggestions_HOOK(). @@ -60,5 +61,7 @@ function template_preprocess_search_result(&$variables) { // Provide separated and grouped meta information.. $variables['info_split'] = $info; $variables['info'] = implode(' - ', $info); + $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(); } diff --git a/core/themes/bartik/bartik.theme b/core/themes/bartik/bartik.theme index 3216ab2..f8e033a 100644 --- a/core/themes/bartik/bartik.theme +++ b/core/themes/bartik/bartik.theme @@ -133,9 +133,9 @@ function bartik_preprocess_menu(&$variables) { function bartik_preprocess_field(&$variables) { $element = $variables['element']; if ($element['#field_type'] == 'taxonomy_term_reference') { - $variables['title_attributes']['class'][] = 'field-label'; + $variables['title_attributes']->addClass('field-label'); if ($variables['element']['#label_display'] == 'inline') { - $variables['title_attributes']['class'][] = 'inline'; + $variables['title_attributes']->addClass('inline'); } } } diff --git a/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig b/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig index a8e94e2..8051999 100644 --- a/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig +++ b/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig @@ -22,8 +22,8 @@ {{ label }} {% endif %} - {% for item in items %} - {{ item.content }} + {% for delta, item in items %} + {{ item }} {% endfor %}