diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 13a5154..37a7bb5 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1222,8 +1222,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'), @@ -1584,6 +1582,9 @@ function template_preprocess_field(&$variables, $hook) { $variables['items'][$delta]['attributes'] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes); $delta++; } + + $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 6850fcb..aa8ed7c 100644 --- a/core/lib/Drupal/Core/Theme/ThemeManager.php +++ b/core/lib/Drupal/Core/Theme/ThemeManager.php @@ -355,15 +355,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 f9dd787..1205ce8 100644 --- a/core/modules/block/block.module +++ b/core/modules/block/block.module @@ -12,6 +12,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,8 @@ 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(); + $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : new Attribute(); } /** diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index ea918bd..9f5ed06 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; @@ -708,6 +709,8 @@ 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'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : new Attribute(); + $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 b50a6cd..dba393a 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -7,6 +7,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\Template\Attribute; /** * Implements hook_theme_suggestions_HOOK(). @@ -64,5 +65,7 @@ function template_preprocess_search_result(&$variables) { '#template' => '{{ info|safe_join(" - ") }}', '#context' => array('info' => $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(); }