diff --git a/core/modules/file/file.js b/core/modules/file/file.js index abf99fe..c1283ee 100644 --- a/core/modules/file/file.js +++ b/core/modules/file/file.js @@ -107,15 +107,16 @@ if (extensionPattern.length > 1 && event.target.value.length > 0) { var acceptableMatch = new RegExp('\\.(' + extensionPattern + ')$', 'i'); var testSubjects; - if(event.target.files) { + if (event.target.files) { testSubjects = event.target.files; - } else { + } + else { testSubjects = [{name: event.target.value}]; } var invalidFiles = []; - for(var i = 0; i < testSubjects.length; i++) { + for (var i = 0; i < testSubjects.length; i++) { var testSubject = testSubjects[i]; - if(!acceptableMatch.test(testSubject.name)) { + if (!acceptableMatch.test(testSubject.name)) { // According to the specifications of HTML5, a file upload control // should not reveal the real local path to the file that a user // has selected. Some web browsers implement this restriction by @@ -130,9 +131,9 @@ var error = Drupal.formatPlural(invalidFiles.length, 'The selected file %filename cannot be uploaded.', '@count of the selected files cannot be uploaded.', { '%filename': invalidFiles[0] }); - if(invalidFiles.length > 1) { + if (invalidFiles.length > 1) { error += ''; diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index abd0eec..5abd41c 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -280,15 +280,19 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen } /** - * Form API callback. Attaches data- attributes to the file input field - * for JavaScript's benefit. + * Form API callback. Attaches data- attributes to the file input field for + * JavaScript's benefit. * - * @param array $element The FileWidget's render array + * @param array $element + * The FileWidget's render array. * @param FormStateInterface $form_state - * @return array The updated render array + * The form state. + * + * @return array + * The updated render array. */ - public function addValidateDataForJs($element, FormStateInterface &$form_state) { - // file extensions go on the ManagedFile's 'upload' child as data- attribute + public function addValidateDataForJs(array $element, FormStateInterface &$form_state) { + // File extensions go on the ManagedFile's 'upload' child as data attribute. if (is_array($element['upload']) && !empty($element['#upload_validators']['file_validate_extensions'])) { $element['upload']['#attributes']['data-drupal-validate-extensions'] = $element['#upload_validators']['file_validate_extensions'][0]; } @@ -398,7 +402,8 @@ public static function process($element, FormStateInterface $form_state, $form) ); if (isset($item['display'])) { $element['display']['#value'] = $item['display'] ? '1' : ''; - } else { + } + else { $element['display']['#value'] = $element['#display_default']; } } diff --git a/core/modules/file/src/Tests/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php index e3d2626..6a245c8 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -347,7 +347,7 @@ function testWidgetValidation() { $test_file_image = $this->getTestFile('image'); $name = 'files[' . $field_name . '_0]'; - // check field is marked with expected attr for client-side validation + // Check field is marked with expected attr for client-side validation. $this->assertFieldByXPath('//input[@type="file" and @data-drupal-validate-extensions="txt"]', null, 'data-drupal-validate-extensions is present'); // Upload file with incorrect extension, check for validation error.