summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2016-09-20 19:16:27 (GMT)
committerwebchick2016-09-20 19:16:27 (GMT)
commitb714d00d7f0562bf88260b407a23224279e676ae (patch)
treecb89ab326b6771d307b2b500e9ff7220cff82ad3
parentda5e5502c0b029b4395643d6f7563bafa356508e (diff)
Issue #2307451 by martin_q, Gábor Hojtsy, Manjit.Singh, Dave Reid, iantresman, giorgio79, swentel, slashrsm, Bojhan, yoroy, rymo, xjm, Wim Leers, Saphyel, tstoeckler: Image file fields do not limit accepted file types in HTML
-rw-r--r--core/modules/file/src/Element/ManagedFile.php4
-rw-r--r--core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php3
-rw-r--r--core/modules/image/src/Tests/ImageFieldWidgetTest.php1
3 files changed, 8 insertions, 0 deletions
diff --git a/core/modules/file/src/Element/ManagedFile.php b/core/modules/file/src/Element/ManagedFile.php
index 426f40c..f465b18 100644
--- a/core/modules/file/src/Element/ManagedFile.php
+++ b/core/modules/file/src/Element/ManagedFile.php
@@ -49,6 +49,7 @@ class ManagedFile extends FormElement {
'#attached' => [
'library' => ['file/drupal.file'],
],
+ '#accept' => NULL,
];
}
@@ -308,6 +309,9 @@ class ManagedFile extends FormElement {
'#weight' => -10,
'#error_no_message' => TRUE,
];
+ if (!empty($element['#accept'])) {
+ $element['upload']['#attributes'] = ['accept' => $element['#accept']];
+ }
if (!empty($fids) && $element['#files']) {
foreach ($element['#files'] as $delta => $file) {
diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
index 2fe5841..f881419 100644
--- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
+++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
@@ -123,6 +123,9 @@ class ImageWidget extends FileWidget {
$extensions = array_intersect(explode(' ', $extensions), $supported_extensions);
$element['#upload_validators']['file_validate_extensions'][0] = implode(' ', $extensions);
+ // Add mobile device image capture acceptance.
+ $element['#accept'] = 'image/*';
+
// Add properties needed by process() method.
$element['#preview_image_style'] = $this->getSetting('preview_image_style');
$element['#title_field'] = $field_settings['title_field'];
diff --git a/core/modules/image/src/Tests/ImageFieldWidgetTest.php b/core/modules/image/src/Tests/ImageFieldWidgetTest.php
index 52d9e4d..85e764b 100644
--- a/core/modules/image/src/Tests/ImageFieldWidgetTest.php
+++ b/core/modules/image/src/Tests/ImageFieldWidgetTest.php
@@ -25,6 +25,7 @@ class ImageFieldWidgetTest extends ImageFieldTestBase {
$this->createImageField($field_name, 'article', array(), $field_settings, array(), array(), 'Image test on [site:name]');
$this->drupalGet('node/add/article');
$this->assertNotEqual(0, count($this->xpath('//div[contains(@class, "field--widget-image-image")]')), 'Image field widget found on add/node page', 'Browser');
+ $this->assertNotEqual(0, count($this->xpath('//input[contains(@accept, "image/*")]')), 'Image field widget limits accepted files.', 'Browser');
$this->assertNoText('Image test on [site:name]');
}