summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2013-12-26 15:05:32 (GMT)
committerAlex Pott2013-12-26 15:05:32 (GMT)
commit185c50b124e6f3c22ff72422d07d6f5f64ea7c2f (patch)
treee1e93ce33b9cc6900b4a5c2cab8344e8b782afe9
parent4f2d2ab709c833e405203fa552b8321bae09dd7b (diff)
Issue #2050113 by swentel, longwave, Hydra, yched, marthinal, netsensei: PHP notice on multiple items image field.
-rw-r--r--core/modules/file/lib/Drupal/file/Plugin/Field/FieldWidget/FileWidget.php5
-rw-r--r--core/modules/image/lib/Drupal/image/Plugin/Field/FieldWidget/ImageWidget.php3
-rw-r--r--core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php15
3 files changed, 22 insertions, 1 deletions
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 948a06d..a7c8d30 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 @@ class FileWidget extends WidgetBase {
$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 c3afdbb..0ecca82 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 @@ class ImageWidget extends FileWidget {
$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 @@ class ImageWidget extends FileWidget {
}
}
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 0071179..aa54d89 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 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
'%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())));
}
/**