Commit b714d00d authored by webchick's avatar webchick

Issue #2307451 by martin_q, Gábor Hojtsy, Manjit.Singh, Dave Reid, iantresman,...

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
parent da5e5502
......@@ -49,6 +49,7 @@ public function getInfo() {
'#attached' => [
'library' => ['file/drupal.file'],
],
'#accept' => NULL,
];
}
......@@ -308,6 +309,9 @@ public static function processManagedFile(&$element, FormStateInterface $form_st
'#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) {
......
......@@ -123,6 +123,9 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
$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'];
......
......@@ -25,6 +25,7 @@ public function testWidgetElement() {
$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]');
}
......
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