Commit d1868836 authored by catch's avatar catch

Issue #2604220 by yched, swentel, Cottser: PHP notice for single value image...

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
parent 934567b7
......@@ -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);
}
......
......@@ -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 @@ public function testDefaultImages() {
)
);
// 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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment