commit e5123f52b507b19c9fc7520aa9e4079f14eb5a4d Author: Joel Pittet Date: Wed Sep 3 20:45:32 2014 -0700 add back default_attributes clone diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 1f28b53..ac79094 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -212,6 +212,8 @@ function list_themes($refresh = FALSE) { * @see template_preprocess() */ function _theme($hook, $variables = array()) { + static $default_attributes; + $module_handler = \Drupal::moduleHandler(); $active_theme = \Drupal::theme()->getActiveTheme(); @@ -412,8 +414,17 @@ 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)) { - $variables['attributes'] = new Attribute($variables['attributes']); + if ($variables['attributes']) { + $variables['attributes'] = new Attribute($variables['attributes']); + } + else { + // Create empty attributes. + $variables['attributes'] = clone $default_attributes; + } } // Render the output using the template file. @@ -2112,6 +2123,11 @@ function template_preprocess_field(&$variables, $hook) { $variables['title_attributes']['class'][] = 'visually-hidden'; } + static $default_attributes; + if (!isset($default_attributes)) { + $default_attributes = new Attribute; + } + // Modules (e.g., rdf.module) can add field item attributes (to // $item->_attributes) within hook_entity_prepare_view(). Some field // formatters move those attributes into some nested formatter-specific @@ -2120,11 +2136,11 @@ function template_preprocess_field(&$variables, $hook) { // formatters leave them within $element['#items'][$delta]['_attributes'] to // be rendered on the item wrappers provided by field.html.twig. foreach ($variables['items'] as $delta => $item) { - $variables['item_attributes'][$delta] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : new Attribute(); + $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']) : new Attribute(); - $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']) : clone $default_attributes; + $variables['content_attributes'] = isset($variables['content_attributes']) ? new Attribute($variables['content_attributes']) : clone $default_attributes; } /**