diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 64bd59b..1dd07e3 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1530,7 +1530,7 @@ function template_preprocess_field(&$variables, $hook) {
}
// Merge attributes when a single-value field has a visible label.
if ($element['#label_display'] != 'hidden' && !$variables['multiple'] && is_object($element['#items'][0])) {
- $element['#items'][0]->_attributes = NestedArray::mergeDeep($variables['content_attributes'], (array) $element['#items'][0]->_attributes);
+ $variables['content_attributes'] = NestedArray::mergeDeep($variables['content_attributes'], (array) $element['#items'][0]->_attributes);
}
// We want other preprocess functions and the theme implementation to have
diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
index 7be4301..d1ba313 100644
--- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
+++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
@@ -189,13 +189,10 @@ public function testEntityFormatter() {
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
// Test the first field item.
- $expected_rendered_name_field_1 = '
' . $this->referencedEntity->label() . '
-';
- $expected_rendered_body_field_1 = '
-';
+ $expected_rendered_name_field_1 = '
+' . $this->referencedEntity->label() . '
';
+ $expected_rendered_body_field_1 = '
+';
$renderer->renderRoot($build[0]);
$this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field_1 . $expected_rendered_body_field_1, sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$expected_cache_tags = Cache::mergeTags(\Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTags(), $this->referencedEntity->getCacheTags());
diff --git a/core/modules/system/templates/field.html.twig b/core/modules/system/templates/field.html.twig
index 10f21e0..248dd8e 100644
--- a/core/modules/system/templates/field.html.twig
+++ b/core/modules/system/templates/field.html.twig
@@ -55,13 +55,15 @@
{{ label }}:
{% if multiple %}
-
- {% endif %}
+
+ {% for item in items %}
+
{{ item.content }}
+ {% endfor %}
+
+ {% else %}
{% for item in items %}
-
{{ item.content }}
+
{{ item.content }}
{% endfor %}
- {% if multiple %}
-
{% endif %}
{% endif %}
diff --git a/core/themes/classy/templates/field/field.html.twig b/core/themes/classy/templates/field/field.html.twig
index 953546f..29c2b97 100644
--- a/core/themes/classy/templates/field/field.html.twig
+++ b/core/themes/classy/templates/field/field.html.twig
@@ -53,6 +53,7 @@
]
%}
+{% spaceless %}
{% if label_hidden %}
{% if multiple %}
@@ -70,12 +71,15 @@
{{ label }}:
{% if multiple %}
- {% endif %}
- {% for item in items %}
-
{{ item.content }}
- {% endfor %}
- {% if multiple %}
+ {% for item in items %}
+
{{ item.content }}
+ {% endfor %}
+ {% else %}
+ {% for item in items %}
+
{{ item.content }}
+ {% endfor %}
{% endif %}
{% endif %}
+{% endspaceless %}