From bfcba532775b04644140e711199629bf943ebcd9 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Fri, 25 Sep 2015 16:54:05 +0200
Subject: [PATCH] Issue #2550225 by swentel, yched, Wim Leers, aspilicious:
 quickedit_test_entity_view_alter() creates a non compliant field render array

---
 core/includes/theme.inc                      | 4 ++--
 core/lib/Drupal/Core/Field/FormatterBase.php | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/core/includes/theme.inc b/core/includes/theme.inc
index 24c9d7e6a8b6..454414d373f3 100644
--- a/core/includes/theme.inc
+++ b/core/includes/theme.inc
@@ -1480,7 +1480,7 @@ function template_preprocess_field(&$variables, $hook) {
   // readers.
   $variables['label'] = $element['#title'];
 
-  $variables['multiple'] = $element['#items']->getFieldDefinition()->getFieldStorageDefinition()->isMultiple();
+  $variables['multiple'] = $element['#is_multiple'];
 
   static $default_attributes;
   if (!isset($default_attributes)) {
@@ -1488,7 +1488,7 @@ function template_preprocess_field(&$variables, $hook) {
   }
 
   // Merge attributes when a single-value field has a hidden label.
-  if ($element['#label_display'] == 'hidden' && !$variables['multiple'] && is_object($element['#items'][0])) {
+  if ($element['#label_display'] == 'hidden' && !$variables['multiple']) {
     $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], (array) $element['#items'][0]->_attributes);
   }
 
diff --git a/core/lib/Drupal/Core/Field/FormatterBase.php b/core/lib/Drupal/Core/Field/FormatterBase.php
index a6c8cc8caea4..a44b8a910511 100644
--- a/core/lib/Drupal/Core/Field/FormatterBase.php
+++ b/core/lib/Drupal/Core/Field/FormatterBase.php
@@ -99,6 +99,7 @@ public function view(FieldItemListInterface $items) {
         '#object' => $entity,
         '#items' => $items,
         '#formatter' => $this->getPluginId(),
+        '#is_multiple' => $this->fieldDefinition->getFieldStorageDefinition()->isMultiple(),
       );
 
       $elements = array_merge($info, $elements);
-- 
GitLab