diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 0f281b4..ed88892 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -990,9 +990,16 @@ function template_preprocess_field(&$variables, $hook) { if (!isset($default_attributes)) { $default_attributes = new Attribute; } - $variables['attributes'] = new Attribute; - $variables['title_attributes'] = new Attribute; - $variables['content_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'] = 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); foreach ($variables['items'] as $delta => $item) { $variables['item_attributes'][$delta] = isset($variables['item_attributes'][$delta]) ? new Attribute($variables['item_attributes'][$delta]) : clone($default_attributes); } diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 526ef66..8e4d278 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -406,6 +406,12 @@ function rdf_preprocess_field(&$variables) { $variables['item_attributes'][$delta]['resource'] = file_create_url($item['entity']->getFileUri()); } } + // Convert the item_attributes for this field item back into an Attribute + // object for printing. This is necessary because at this time this + // preprocess function overwrites $variables['item_attributes'][$delta], + // which is initialized as an Attribute object in + // template_preprocess_field(). + $variables['item_attributes'][$delta] = new Attribute($variables['item_attributes'][$delta]); } } }