Commit 185c50b1 authored by alexpott's avatar alexpott

Issue #2050113 by swentel, longwave, Hydra, yched, marthinal, netsensei: PHP...

Issue #2050113 by swentel, longwave, Hydra, yched, marthinal, netsensei: PHP notice on multiple items image field.
parent 4f2d2ab7
......@@ -152,6 +152,11 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f
$elements['#field_name'] = $element['#field_name'];
$elements['#language'] = $element['#language'];
$elements['#display_field'] = (bool) $this->getFieldSetting('display_field');
// The field settings include defaults for the field type. However, this
// widget is a base class for other widgets (e.g., ImageWidget) that may
// act on field types without these expected settings.
$field_settings = $this->getFieldSettings() + array('display_field' => NULL);
$elements['#display_field'] = (bool) $field_settings['display_field'];
// Add some properties that will eventually be added to the file upload
// field. These are added here so that they may be referenced easily
......
......@@ -81,6 +81,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f
$cardinality = $this->fieldDefinition->getCardinality();
$file_upload_help = array(
'#theme' => 'file_upload_help',
'#description' => '',
'#upload_validators' => $elements[0]['#upload_validators'],
'#cardinality' => $cardinality,
);
......@@ -92,7 +93,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f
}
}
else {
$elements['#file_upload_description'] = drupal_render($file_upload_help);
$elements['#file_upload_description'] = $file_upload_help;
}
return $elements;
......
......@@ -7,6 +7,8 @@
namespace Drupal\image\Tests;
use Drupal\Core\Field\FieldDefinitionInterface;
/**
* Test class to check that formatters and display settings are working.
*/
......@@ -221,6 +223,19 @@ function testImageFieldSettings() {
'%max' => $schema['columns']['title']['length'],
'%length' => $test_size,
)));
// Set cardinality to unlimited and add upload a second image.
// The image widget is extending on the file widget, but the image field
// type does not have the 'display_field' setting which is expected by
// the file widget. This resulted in notices before when cardinality is not
// 1, so we need to make sure the file widget prevents these notices by
// providing all settings, even if they are not used.
// @see FileWidget::formMultipleElements().
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/field', array('field[cardinality]' => FieldDefinitionInterface::CARDINALITY_UNLIMITED), t('Save field settings'));
$edit = array();
$edit['files[' . $field_name . '_1][]'] = drupal_realpath($test_image->uri);
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published'));
$this->assertText(format_string('Article @title has been updated.', array('@title' => $node->getTitle())));
}
/**
......
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