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

8.1.x
Nathaniel Catchpole 2015-12-29 21:51:58 +09:00
parent 934567b7a9
commit d1868836f4
2 changed files with 9 additions and 1 deletions

View File

@ -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);
}

View File

@ -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);