diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 2786774..dcb9236 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -2092,19 +2092,6 @@ function template_preprocess_field(&$variables, $hook) { // readers. $variables['label'] = String::checkPlain($element['#title']); - // We want other preprocess functions and the theme implementation to have - // fast access to the field item render arrays. The item render array keys - // (deltas) should always be numerically indexed starting from 0, and looping - // on those keys is faster than calling - // \Drupal\Core\Render\Element::children() or looping on all keys within - // $element, since that requires traversal of all element properties. - $variables['items'] = array(); - $delta = 0; - while (!empty($element[$delta])) { - $variables['items'][$delta] = $element[$delta]; - $delta++; - } - // Add default CSS classes. Since there can be many fields rendered on a page, // save some overhead by calling strtr() directly instead of // drupal_html_class(). @@ -2118,6 +2105,7 @@ function template_preprocess_field(&$variables, $hook) { 'field-type-' . $variables['field_type_css'], 'field-label-' . $element['#label_display'], ); + // Add a "clearfix" class to the wrapper since we float the label and the // field items in field.module.css if the label is inline. if ($element['#label_display'] == 'inline') { @@ -2134,15 +2122,26 @@ function template_preprocess_field(&$variables, $hook) { $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 - // element in order have them rendered on the desired HTML element (e.g., on - // 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. - foreach ($variables['items'] as $delta => $item) { - $variables['item_attributes'][$delta] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes); + // We want other preprocess functions and the theme implementation to have + // fast access to the field item render arrays. The item render array keys + // (deltas) should always be numerically indexed starting from 0, and looping + // on those keys is faster than calling element_children() or looping on all + // keys within $element, since that requires traversal of all element + // properties. + $variables['items'] = array(); + $delta = 0; + while (!empty($element[$delta])) { + $variables['items'][$delta]['value'] = $element[$delta]; + + // 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 + // element in order have them rendered on the desired HTML element (e.g., on + // 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++; } } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index dbe3bee..6ab7692 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -868,7 +868,7 @@ function comment_preprocess_field(&$variables) { $variables['title_attributes']['class'][] = 'title'; // Append additional attributes (eg. RDFa) from the first field item. - $variables['attributes'] += $variables['item_attributes'][0]->storage(); + $variables['attributes'] += $variables['items'][0]['attributes']->storage(); // Create separate variables for the comments and comment form. $variables['comments'] = $element[0]['comments']; diff --git a/core/modules/node/templates/field--node--title.html.twig b/core/modules/node/templates/field--node--title.html.twig index 25432c0..8051544 100644 --- a/core/modules/node/templates/field--node--title.html.twig +++ b/core/modules/node/templates/field--node--title.html.twig @@ -8,11 +8,17 @@ * * Available variables: * - attributes: HTML attributes for the containing span element. - * - items: List of all the field items. + * - items: List of all the field items. Each item contains: + * - attributes: List of HTML attributes for each item. + * - value: The field item value. * * @see field.html.twig * * @ingroup themeable */ #} -{{ items }} + + {%- for item in items -%} + {{ item.value }} + {%- endfor -%} + diff --git a/core/modules/system/templates/field.html.twig b/core/modules/system/templates/field.html.twig index d38b028..559af33f 100644 --- a/core/modules/system/templates/field.html.twig +++ b/core/modules/system/templates/field.html.twig @@ -21,8 +21,9 @@ * - title_attributes: HTML attributes for the title. * - label: The label for the field. * - content_attributes: HTML attributes for the content. - * - items: List of all the field items. - * - item_attributes: List of HTML attributes for each item. + * - items: List of all the field items. Each item contains: + * - attributes: List of HTML attributes for each item. + * - value: The field item's value. * * @see template_preprocess_field() * @@ -31,11 +32,11 @@ #} {% if not label_hidden %} -
{{ label }}: 
+ {{ label }}:  {% endif %} -
- {% for delta, item in items %} -
{{ item }}
+ + {% for item in items %} + {{ item.value }}
{% endfor %} 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 4c579ee..a818519 100644 --- a/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig +++ b/core/themes/bartik/templates/field--taxonomy-term-reference.html.twig @@ -9,20 +9,21 @@ * - title_attributes: HTML attributes for the label. * - label: The label for the field. * - content_attributes: HTML attributes for the content. - * - items: List of all the field items. - * - item_attributes: List of HTML attributes for each item. + * - items: List of all the field items. Each item contains: + * - attributes: List of HTML attributes for each item. + * - value: The field item's value. * * @see template_preprocess_field() * @see bartik_preprocess_field() */ #} -
+ {% if not label_hidden %} {{ label }}: {% endif %} -