Issue #1843728 by jenlampton, thund3rbox, mr.baileys, Cottser: Remove template_process_field().

8.0.x
Nathaniel Catchpole 2013-07-11 10:26:38 +01:00
parent 45418a7ca0
commit 54b703ed4b
2 changed files with 13 additions and 14 deletions

View File

@ -984,24 +984,18 @@ function template_preprocess_field(&$variables, $hook) {
'field__' . $element['#bundle'],
'field__' . $element['#field_name'] . '__' . $element['#bundle'],
);
}
/**
* Theme process function for theme_field() and field.html.twig.
*
* @see theme_field()
* @see field.html.twig
*/
function template_process_field(&$variables, $hook) {
static $default_attributes;
// The default theme implementation is a function, so template_process() does
// not automatically run, so we need to flatten the classes and attributes
// here. For best performance, only instantiate Drupal\Core\Template\Attribute
// when needed, and note that template_preprocess_field() does not initialize
// the *_attributes variables.
if (!isset($default_attributes)) {
$default_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);
@ -1070,7 +1064,6 @@ function template_process_field(&$variables, $hook) {
* - attributes: A string containing the attributes for the wrapping div.
*
* @see template_preprocess_field()
* @see template_process_field()
* @see field.html.twig
*
* @ingroup themeable

View File

@ -350,6 +350,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]);
}
}
}