- Issue created by @godotislate
- Status changed to Needs review
2 months ago 8:46pm 23 April 2024
When a file or image field on an entity is configured to use s3fs_cors_* field widgets, the file upload input field DOM element in the widget is not being populated with the configured allowed file extensions for the entity field. Then when the input is clicked, the browser's file browser modal does not filter files for the correct extensions. Users can easily upload the wrong file type by mistake. Though a validation error appears when a wrong file is uploaded, submit buttons on the form that were disabled by the upload are not re-enabled, which means users may have to reload the page to be able to interact with those parts of the form again.
Note that the patch for
accept="image/*"
attribute. Markup will look something like this: <input class="s3fs-cors-upload js-form-file form-file form-element form-element--type-file form-element--api-file" data-drupal-selector="edit-field-image-0-upload" type="file" id="edit-field-image-0-upload" name="files[field_image_0]" size="22" data-once="s3fs-cors-auto-upload">
The missing accept="image/*"
attribute on the input is happening because the render array attributes for the element are being clobbered in Drupal\s3fs_cors\Element\S3fsCorsFile::processManagedFile()
with this line: $element['upload']['#attributes'] = ['class' => ['s3fs-cors-upload']];
. $element['upload']['#attributes']
could already be set by the call to parent::processManagedFile()
directly before this. The fix would be safely add the class attribute to the existing array.
For the disabled button issue, the fix would be Drupal.s3fsCors.triggerUploadButton() in s3fs_cors.js for this code:
if (error) {
$(this).closest('div.js-form-managed-file').prepend('<div class="messages messages--error file-upload-js-error" aria-live="polite">' + error + '</div>');
this.value = '';
return;
}
The submit buttons need to be re-enabled before `return;`
Needs review
1.0
Documentation