From d1868836f40e366e392644dce970e29a12de751d Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole Date: Tue, 29 Dec 2015 21:51:58 +0900 Subject: [PATCH] Issue #2604220 by yched, swentel, Cottser: PHP notice for single value image field configured with a default image (no image present) and a hidden label --- core/includes/theme.inc | 2 +- .../image/src/Tests/ImageFieldDefaultImagesTest.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 4f1ffda0a70e..cdfaaa9d7af5 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1535,7 +1535,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']) { + if ($element['#label_display'] == 'hidden' && !$variables['multiple'] && !empty($element['#items'][0]->_attributes)) { $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], (array) $element['#items'][0]->_attributes); } diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php index c33ca1e22a72..ee47e3069890 100644 --- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php @@ -7,6 +7,7 @@ namespace Drupal\image\Tests; use Drupal\Component\Utility\Unicode; +use Drupal\Core\Entity\Entity\EntityViewDisplay; use Drupal\file\Entity\File; /** @@ -162,6 +163,13 @@ class ImageFieldDefaultImagesTest extends ImageFieldTestBase { ) ); + // Also check that the field renders without warnings when the label is + // hidden. + EntityViewDisplay::load('node.article.default') + ->setComponent($field_name, array('label' => 'hidden', 'type' => 'image')) + ->save(); + $this->drupalGet('node/' . $article->id()); + // Confirm that the image default is shown for a new page node. $page = $this->drupalCreateNode(array('type' => 'page')); $page_built = $this->drupalBuildEntityView($page);