diff --git a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php index 948a06d9a22e04d0658b635416831897dc362df5..a7c8d3028f8d4101a2536e6f8c98d30d32e0c5f2 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php @@ -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 diff --git a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldWidget/ImageWidget.php index c3afdbb8d0e6ce7f1c901400313ed6d7cb7cd650..0ecca824c3b4c8b1c8177b9ec230e468680e6f3c 100644 --- a/core/modules/image/lib/Drupal/image/Plugin/Field/FieldWidget/ImageWidget.php +++ b/core/modules/image/lib/Drupal/image/Plugin/Field/FieldWidget/ImageWidget.php @@ -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; diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index 0071179c235ebe45b984d50e6e9f073417080368..aa54d897689190b18da86ae0c5efc9c544bec5f7 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -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()))); } /**