Issue #3418781 by sukr_s, Charles Belov, smustgrave: UI refers to "files" when you can only upload one file

merge-requests/5477/merge
catch 2024-03-26 10:09:02 +00:00
parent 91840da9a8
commit f4bf71d660
2 changed files with 14 additions and 5 deletions

View File

@ -165,7 +165,9 @@ class FileUploadForm extends AddFormBase {
// @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()

View File

@ -208,9 +208,12 @@ class WidgetUploadTest extends MediaLibraryTestBase {
// 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 @@ class WidgetUploadTest extends MediaLibraryTestBase {
// 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.