diff --git a/core/modules/media_library/src/Form/FileUploadForm.php b/core/modules/media_library/src/Form/FileUploadForm.php index abea90f0cc0d293ffbee8a79f0a8b406e340b51d..fd2bc14a419cb4fe1076d4068420e6fe3fdf40e3 100644 --- a/core/modules/media_library/src/Form/FileUploadForm.php +++ b/core/modules/media_library/src/Form/FileUploadForm.php @@ -165,7 +165,9 @@ protected function buildInputElement(array $form, FormStateInterface $form_state // @todo Move validation in https://www.drupal.org/node/2988215 '#process' => array_merge(['::validateUploadElement'], $process, ['::processUploadElement']), '#upload_validators' => $item->getUploadValidators(), - '#multiple' => TRUE, + // Set multiple to true only if available slots is not exactly one + // to ensure correct language (singular or plural) in UI + '#multiple' => $slots != 1 ? TRUE : FALSE, // Do not limit the number uploaded. There is validation based on the // number selected in the media library that prevents overages. // @see Drupal\media_library\Form\AddFormBase::updateLibrary() diff --git a/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php b/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php index 5afbb4f5254da0738130c19357f85eff345c47c1..483638746b1d712abf93fc71d7cd63ed922d9493 100644 --- a/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php +++ b/core/modules/media_library/tests/src/FunctionalJavascript/WidgetUploadTest.php @@ -208,9 +208,12 @@ public function testWidgetUpload() { // Assert we can now only upload one more media item. $this->openMediaLibraryForField('field_twin_media'); $this->switchToMediaType('Four'); - // Despite the 'One file only' text, we don't limit the number of uploads. - $this->assertTrue($assert_session->fieldExists('Add file')->hasAttribute('multiple')); + // We set the multiple to FALSE if only one file can be uploaded + $this->assertFalse($assert_session->fieldExists('Add file')->hasAttribute('multiple')); $assert_session->pageTextContains('One file only.'); + $choose_files = $assert_session->elementExists('css', '.form-managed-file'); + $choose_files->hasButton('Choose file'); + $this->assertFalse($choose_files->hasButton('Choose files')); // Assert media type four should only allow jpg files by trying a png file // first. @@ -555,9 +558,13 @@ public function testWidgetUploadAdvancedUi() { // Assert we can now only upload one more media item. $this->openMediaLibraryForField('field_twin_media'); $this->switchToMediaType('Four'); - // Despite the 'One file only' text, we don't limit the number of uploads. - $this->assertTrue($assert_session->fieldExists('Add file')->hasAttribute('multiple')); + + // We set the multiple to FALSE if only one file can be uploaded + $this->assertFalse($assert_session->fieldExists('Add file')->hasAttribute('multiple')); $assert_session->pageTextContains('One file only.'); + $choose_files = $assert_session->elementExists('css', '.form-managed-file'); + $choose_files->hasButton('Choose file'); + $this->assertFalse($choose_files->hasButton('Choose files')); // Assert media type four should only allow jpg files by trying a png file // first.