diff --git a/composer.json b/composer.json index e99780a25997659e33fcdecb1fa402b7fff4ccad..e23a58291fa25dae13e72034c41089f2b3e394b7 100644 --- a/composer.json +++ b/composer.json @@ -109,7 +109,7 @@ "drupal/core-recommended": "^9.0", "drupal/crop": "2.2", "drupal/ctools": "3.7", - "drupal/dropzonejs": "2.5", + "drupal/dropzonejs": "2.6", "drupal/editor_advanced_link": "1.9", "drupal/embed": "1.4", "drupal/entity": "1.2", diff --git a/composer.lock b/composer.lock index ca3c06a373344b126b57b531b767d9fef89072d0..f43fc7e26f5607d7a89a3a507b81973d530d0c5d 100644 --- a/composer.lock +++ b/composer.lock @@ -3510,23 +3510,23 @@ }, { "name": "drupal/dropzonejs", - "version": "2.5.0", + "version": "2.6.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/dropzonejs.git", - "reference": "8.x-2.5" + "reference": "8.x-2.6" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/dropzonejs-8.x-2.5.zip", - "reference": "8.x-2.5", - "shasum": "9918bd8c3c62599ec701be3bbac986741e735859" + "url": "https://ftp.drupal.org/files/projects/dropzonejs-8.x-2.6.zip", + "reference": "8.x-2.6", + "shasum": "3a14b26ade989e00bbbc9f6bbfa364fb5acb9367" }, "require": { "drupal/core": "^8.8 || ^9" }, "require-dev": { - "drupal/entity_browser": "*" + "drupal/entity_browser": "^2.5" }, "suggest": { "enyo/dropzone": "Required to use drupal/dropzonejs. DropzoneJS is an open source library that provides drag’n’drop file uploads with image previews." @@ -3534,8 +3534,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-2.5", - "datestamp": "1614606376", + "version": "8.x-2.6", + "datestamp": "1647857808", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index f767c1726f5bec44a1e1ee0bacb39c6208a548cc..83a97a7e7126690681f64d6bb20c98744387f72a 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -3611,18 +3611,18 @@ }, { "name": "drupal/dropzonejs", - "version": "2.5.0", - "version_normalized": "2.5.0.0", + "version": "2.6.0", + "version_normalized": "2.6.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/dropzonejs.git", - "reference": "8.x-2.5" + "reference": "8.x-2.6" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/dropzonejs-8.x-2.5.zip", - "reference": "8.x-2.5", - "shasum": "9918bd8c3c62599ec701be3bbac986741e735859" + "url": "https://ftp.drupal.org/files/projects/dropzonejs-8.x-2.6.zip", + "reference": "8.x-2.6", + "shasum": "3a14b26ade989e00bbbc9f6bbfa364fb5acb9367" }, "require": { "drupal/core": "^8.8 || ^9" @@ -3636,8 +3636,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-2.5", - "datestamp": "1614606376", + "version": "8.x-2.6", + "datestamp": "1647857808", "security-coverage": { "status": "covered", "message": "Covered by Drupal's security advisory policy" diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 8ff238594d07536083ea99056007165232749d34..e58beca19137d50608c1f82f78bd9c9299a55ad1 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -818,12 +818,12 @@ ), ), 'drupal/dropzonejs' => array( - 'pretty_version' => '2.5.0', - 'version' => '2.5.0.0', + 'pretty_version' => '2.6.0', + 'version' => '2.6.0.0', 'type' => 'drupal-module', 'install_path' => __DIR__ . '/../../web/modules/dropzonejs', 'aliases' => array(), - 'reference' => '8.x-2.5', + 'reference' => '8.x-2.6', 'dev_requirement' => false, ), 'drupal/dropzonejs_eb_widget' => array( diff --git a/web/modules/dropzonejs/README.md b/web/modules/dropzonejs/README.md index 7af1a12dc59bfee3612fa6a40f7d9ade092cf7fe..696e212fca78c04b070b212f7135f15269086054 100644 --- a/web/modules/dropzonejs/README.md +++ b/web/modules/dropzonejs/README.md @@ -36,10 +36,15 @@ installed to the `libraries` folder automatically. #### The composer way 2 -Copy the following into the root `composer.json` file's `repository` key +Add a custom package to the root `composer.json` file. Its `repositories` key +looks like the following. ``` "repositories": [ + { + "type": "composer", + "url": "https://packages.drupal.org/8" + }, { "type": "package", "package": { diff --git a/web/modules/dropzonejs/dropzonejs.info.yml b/web/modules/dropzonejs/dropzonejs.info.yml index 8ffbe6068375cd3f81df1ced422debeb7a9c6aa9..423817c9d1dc9e9aeff2e2ebafb565fa52e239e6 100644 --- a/web/modules/dropzonejs/dropzonejs.info.yml +++ b/web/modules/dropzonejs/dropzonejs.info.yml @@ -6,7 +6,7 @@ package: Media dependencies: - drupal:file -# Information added by Drupal.org packaging script on 2021-03-01 -version: '8.x-2.5' +# Information added by Drupal.org packaging script on 2022-03-21 +version: '8.x-2.6' project: 'dropzonejs' -datestamp: 1614606378 +datestamp: 1647857810 diff --git a/web/modules/dropzonejs/dropzonejs.libraries.yml b/web/modules/dropzonejs/dropzonejs.libraries.yml index 1a4fe857b5f427477947cbaf5adc11bffcf91cd5..dff51fe78648bb1a9da2b345efc117cb7470b81d 100644 --- a/web/modules/dropzonejs/dropzonejs.libraries.yml +++ b/web/modules/dropzonejs/dropzonejs.libraries.yml @@ -26,3 +26,10 @@ integration: - core/drupalSettings - core/underscore - dropzonejs/dropzonejs + +media_library: + version: VERSION + js: + js/dropzone.media_library.js: {} + dependencies: + - dropzonejs/integration diff --git a/web/modules/dropzonejs/dropzonejs.module b/web/modules/dropzonejs/dropzonejs.module index 7f44502ef50f30e32d5ea74a0dd33f1e73d7564c..004a256ca4dfd6976fcaafbd61518b32c4181ac9 100644 --- a/web/modules/dropzonejs/dropzonejs.module +++ b/web/modules/dropzonejs/dropzonejs.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\dropzonejs\Form\DropzoneJsUploadForm; /** * Implements hook_help(). @@ -113,3 +114,24 @@ function dropzonejs_library_info_alter(&$libraries, $extension) { } } } + +/** + * Implements hook_media_source_info_alter(). + */ +function dropzonejs_media_source_info_alter(array &$sources) { + if (isset($sources['image'])) { + $sources['image']['forms']['media_library_add'] = DropzoneJsUploadForm::class; + } + + if (isset($sources['video_file'])) { + $sources['video_file']['forms']['media_library_add'] = DropzoneJsUploadForm::class; + } + + if (isset($sources['audio_file'])) { + $sources['audio_file']['forms']['media_library_add'] = DropzoneJsUploadForm::class; + } + + if (isset($sources['file'])) { + $sources['file']['forms']['media_library_add'] = DropzoneJsUploadForm::class; + } +} diff --git a/web/modules/dropzonejs/js/dropzone.integration.js b/web/modules/dropzonejs/js/dropzone.integration.js index b30d11e7965e8c08c48f4b1f7dd4f2e46d11b454..e640cddac513db749eee84b7633b85357049a4fc 100644 --- a/web/modules/dropzonejs/js/dropzone.integration.js +++ b/web/modules/dropzonejs/js/dropzone.integration.js @@ -15,7 +15,7 @@ attach: function (context) { Dropzone.autoDiscover = false; - $('.dropzone-enable').each(function() { + $('.dropzone-enable', context).each(function () { var selector = $(this); selector.addClass('dropzone'); diff --git a/web/modules/dropzonejs/js/dropzone.media_library.js b/web/modules/dropzonejs/js/dropzone.media_library.js new file mode 100644 index 0000000000000000000000000000000000000000..4f620a1d787fbf0fd52c23a4dd15c86cd29932e0 --- /dev/null +++ b/web/modules/dropzonejs/js/dropzone.media_library.js @@ -0,0 +1,48 @@ +/** + * @file + * dropzonejs_eb_widget.common.js + * + * Bundles various dropzone eb widget behaviours. + */ + +(function ($, Drupal, drupalSettings) { + 'use strict'; + + Drupal.behaviors.dropzonejsPostIntegrationMediaLibrary = { + attach: function (context) { + if (typeof drupalSettings.dropzonejs.instances !== 'undefined') { + _.each(drupalSettings.dropzonejs.instances, function (item) { + if (typeof item.instance !== 'undefined') { + + var $form = $(item.instance.element).parents('form'); + + item.instance.on('queuecomplete', function () { + var dzInstance = item.instance; + var filesInQueue = dzInstance.getQueuedFiles(); + var acceptedFiles; + var i; + + if (filesInQueue.length === 0) { + acceptedFiles = dzInstance.getAcceptedFiles(); + + // Ensure that there are some files that should be submitted. + if (acceptedFiles.length > 0 && dzInstance.getUploadingFiles().length === 0) { + // First submit accepted files and clear them from list of + // dropped files afterwards. + $form.find('[id="auto_select_handler"]') + .trigger('auto_select_media_library_widget'); + + // Remove accepted files -> because they are submitted. + for (i = 0; i < acceptedFiles.length; i++) { + dzInstance.removeFile(acceptedFiles[i]); + } + } + } + }); + } + }); + } + } + }; + +}(jQuery, Drupal, drupalSettings)); diff --git a/web/modules/dropzonejs/modules/eb_widget/dropzonejs_eb_widget.info.yml b/web/modules/dropzonejs/modules/eb_widget/dropzonejs_eb_widget.info.yml index 3c56c35769d31eba1d10e9dc70b5d9a877b9775e..a8da51c7c2171c420f9846f3d8df329f6ec1003e 100644 --- a/web/modules/dropzonejs/modules/eb_widget/dropzonejs_eb_widget.info.yml +++ b/web/modules/dropzonejs/modules/eb_widget/dropzonejs_eb_widget.info.yml @@ -9,7 +9,7 @@ dependencies: - entity_browser:entity_browser -# Information added by Drupal.org packaging script on 2021-03-01 -version: '8.x-2.5' +# Information added by Drupal.org packaging script on 2022-03-21 +version: '8.x-2.6' project: 'dropzonejs' -datestamp: 1614606378 +datestamp: 1647857810 diff --git a/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php b/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php index 0c18472d48718d56e0d2f9ae4f68440b03b5005c..e4164b71f7d02c1a840977da22cc8810e8f3853e 100644 --- a/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php +++ b/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/DropzoneJsEbWidget.php @@ -131,7 +131,7 @@ protected function setLibraryDiscovery(LibraryDiscoveryInterface $library_discov * {@inheritdoc} */ public function defaultConfiguration() { - return [ + return array_merge(parent::defaultConfiguration(), [ 'upload_location' => 'public://[date:custom:Y]-[date:custom:m]', 'dropzone_description' => $this->t('Drop files here to upload them'), 'max_filesize' => Environment::getUploadMaxSize() / pow(Bytes::KILOBYTE, 2) . 'M', @@ -142,7 +142,7 @@ public function defaultConfiguration() { 'resize_quality' => 1, 'resize_method' => 'contain', 'thumbnail_method' => 'contain', - ] + parent::defaultConfiguration(); + ]); } /** diff --git a/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php b/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php index 3d29558fcf4297ee89479713f07e2e72ff704be6..382e843e313b6af308bc332b958d61e1e1a7ec52 100644 --- a/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php +++ b/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/InlineEntityFormMediaWidget.php @@ -54,9 +54,9 @@ protected function setEntityDisplayRepository(EntityDisplayRepositoryInterface $ * {@inheritdoc} */ public function defaultConfiguration() { - return [ + return array_merge(parent::defaultConfiguration(), [ 'form_mode' => 'default', - ] + parent::defaultConfiguration(); + ]); } /** diff --git a/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/MediaEntityDropzoneJsEbWidget.php b/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/MediaEntityDropzoneJsEbWidget.php index c50c568992af110a09d1d767912dfedee175b095..d619490d8a72fba4bff977ed789281026ee338c4 100644 --- a/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/MediaEntityDropzoneJsEbWidget.php +++ b/web/modules/dropzonejs/modules/eb_widget/src/Plugin/EntityBrowser/Widget/MediaEntityDropzoneJsEbWidget.php @@ -55,9 +55,9 @@ protected function setModuleHandler(ModuleHandlerInterface $moduleHandler) { * {@inheritdoc} */ public function defaultConfiguration() { - return [ + return array_merge(parent::defaultConfiguration(), [ 'media_type' => '', - ] + parent::defaultConfiguration(); + ]); } /** diff --git a/web/modules/dropzonejs/src/DropzoneJsUploadSave.php b/web/modules/dropzonejs/src/DropzoneJsUploadSave.php index 99e1817889b647d72c0f36f8de10e95f2fcc3774..9a300d4a6a9b7f1f160248f8936586f304ec2790 100644 --- a/web/modules/dropzonejs/src/DropzoneJsUploadSave.php +++ b/web/modules/dropzonejs/src/DropzoneJsUploadSave.php @@ -170,24 +170,29 @@ public function createFile($uri, $destination, $extensions, AccountProxyInterfac return FALSE; } - // Prepare destination. - if (!$this->prepareDestination($file, $destination)) { - $this->messenger->addError($this->t('The file could not be uploaded because the destination %destination is invalid.', ['%destination' => $destination])); - return FALSE; - } - - // Move uploaded files from PHP's upload_tmp_dir to destination. - $move_result = $this->fileSystem->move($uri, $file->getFileUri()); - if (!$move_result) { - $this->messenger->addError($this->t('File upload error. Could not move uploaded file.')); - - $this->logger->notice('Upload error. Could not move uploaded file %file to destination %destination.', ['%file' => $file->getFilename(), '%destination' => $file->getFileUri()]); - return FALSE; + if (!empty($destination)) { + // Prepare destination. + if (!$this->prepareDestination($file, $destination)) { + $this->messenger->addError($this->t('The file could not be uploaded because the destination %destination is invalid.', ['%destination' => $destination])); + return FALSE; + } + + // Move uploaded files from PHP's upload_tmp_dir to destination. + $move_result = $this->fileSystem->move($uri, $file->getFileUri()); + if (!$move_result) { + $this->messenger->addError($this->t('File upload error. Could not move uploaded file.')); + + $this->logger->notice('Upload error. Could not move uploaded file %file to destination %destination.', [ + '%file' => $file->getFilename(), + '%destination' => $file->getFileUri(), + ]); + return FALSE; + } + + // Set the permissions on the new file. + $this->fileSystem->chmod($file->getFileUri()); } - // Set the permissions on the new file. - $this->fileSystem->chmod($file->getFileUri()); - return $file; } diff --git a/web/modules/dropzonejs/src/Element/DropzoneJs.php b/web/modules/dropzonejs/src/Element/DropzoneJs.php index 48d24c3c4e749c6c632707790fccd641fa8146fd..2feae5e6da4a2ca218bf8f169d6a1e1368bd1535 100644 --- a/web/modules/dropzonejs/src/Element/DropzoneJs.php +++ b/web/modules/dropzonejs/src/Element/DropzoneJs.php @@ -76,9 +76,6 @@ public function getInfo() { '#theme' => 'dropzonejs', '#theme_wrappers' => ['form_element'], '#tree' => TRUE, - '#attached' => [ - 'library' => ['dropzonejs/integration'], - ], ]; } @@ -86,6 +83,8 @@ public function getInfo() { * Processes a dropzone upload element. */ public static function processDropzoneJs(&$element, FormStateInterface $form_state, &$complete_form) { + // Generate url and collect metadata for CSRF token to be up to date. + $generated_url = Url::fromRoute('dropzonejs.upload')->toString(TRUE); $element['uploaded_files'] = [ '#type' => 'hidden', // @todo Handle defaults. @@ -93,9 +92,10 @@ public static function processDropzoneJs(&$element, FormStateInterface $form_sta // If we send a url with a token through drupalSettings the placeholder // doesn't get replaced, because the actual scripts markup is not there // yet. So we pass this information through a data attribute. - '#attributes' => ['data-upload-path' => Url::fromRoute('dropzonejs.upload')->toString()], + '#attributes' => ['data-upload-path' => $generated_url->getGeneratedUrl()], ]; - + // Apply cacheable metadata to element. + $generated_url->applyTo($element); if (empty($element['#max_filesize'])) { $element['#max_filesize'] = Environment::getUploadMaxSize(); } @@ -129,6 +129,7 @@ public static function preRenderDropzoneJs(array $element) { // Convert the human size input to bytes, convert it to MB and round it. $max_size = round(Bytes::toInt($element['#max_filesize']) / pow(Bytes::KILOBYTE, 2), 2); + $element['#attached']['library'] = ['dropzonejs/integration']; $element['#attached']['drupalSettings']['dropzonejs'] = [ 'instances' => [ // Configuration keys are matched with DropzoneJS configuration diff --git a/web/modules/dropzonejs/src/Form/DropzoneJsUploadForm.php b/web/modules/dropzonejs/src/Form/DropzoneJsUploadForm.php new file mode 100644 index 0000000000000000000000000000000000000000..e485a9cd3651722bc1da650ee17256eb08bbf424 --- /dev/null +++ b/web/modules/dropzonejs/src/Form/DropzoneJsUploadForm.php @@ -0,0 +1,194 @@ +<?php + +namespace Drupal\dropzonejs\Form; + +use Drupal\Component\Utility\Bytes; +use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\Core\Form\FormBuilderInterface; +use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Url; +use Drupal\dropzonejs\DropzoneJsUploadSaveInterface; +use Drupal\media_library\Form\FileUploadForm; +use Symfony\Component\DependencyInjection\ContainerInterface; + +/** + * Creates a form to create media entities from uploaded files. + */ +class DropzoneJsUploadForm extends FileUploadForm { + + /** + * DropzoneJS module upload save service. + * + * @var \Drupal\dropzonejs\DropzoneJsUploadSaveInterface + */ + protected $dropzoneJsUploadSave; + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + $form = parent::create($container); + $form->setDropzoneJsUploadSave($container->get('dropzonejs.upload_save')); + return $form; + } + + /** + * Set the upload service. + * + * @param \Drupal\dropzonejs\DropzoneJsUploadSaveInterface $dropzoneJsUploadSave + * The upload service. + */ + protected function setDropzoneJsUploadSave(DropzoneJsUploadSaveInterface $dropzoneJsUploadSave) { + $this->dropzoneJsUploadSave = $dropzoneJsUploadSave; + } + + /** + * {@inheritdoc} + */ + protected function buildInputElement(array $form, FormStateInterface $form_state) { + $form = parent::buildInputElement($form, $form_state); + // Create a file item to get the upload validators. + $media_type = $this->getMediaType($form_state); + $item = $this->createFileItem($media_type); + $settings = $item->getFieldDefinition()->getSettings(); + $slots = $form['container']['upload']['#cardinality']; + $process = (array) $this->elementInfo->getInfoProperty('dropzonejs', '#process', []); + $form['container']['upload']['#type'] = 'dropzonejs'; + $form['container']['upload']['#process'] = array_merge(['::validateUploadElement'], $process); + $dropzone_specific_properties = [ + '#max_files' => $slots < 1 ? 0 : $slots, + '#max_filesize' => $settings['max_filesize'], + '#extensions' => $settings['file_extensions'], + '#dropzone_description' => $this->t('Drop files here to upload them'), + ]; + $form['container']['upload'] += $dropzone_specific_properties; + + $form['auto_select_handler'] = [ + '#type' => 'hidden', + '#name' => 'auto_select_handler', + '#id' => 'auto_select_handler', + '#attributes' => ['id' => 'auto_select_handler'], + '#submit' => ['::uploadButtonSubmit'], + '#executes_submit_callback' => TRUE, + '#ajax' => [ + 'callback' => '::updateFormCallback', + 'wrapper' => 'media-library-wrapper', + 'event' => 'auto_select_media_library_widget', + // Add a fixed URL to post the form since AJAX forms are automatically + // posted to <current> instead of $form['#action']. + // @todo Remove when https://www.drupal.org/project/drupal/issues/2504115 + // is fixed. + // Follow along with changes in \Drupal\media_library\Form\OEmbedForm. + 'url' => Url::fromRoute('media_library.ui'), + 'options' => [ + 'query' => $this->getMediaLibraryState($form_state)->all() + [ + FormBuilderInterface::AJAX_FORM_REQUEST => TRUE, + ], + ], + ], + ]; + + $form['#attached']['library'][] = 'dropzonejs/widget'; + $form['#attached']['library'][] = 'dropzonejs/media_library'; + + return $form; + } + + /** + * Validates the upload element. + * + * @param array $element + * The upload element. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state. + * + * @return array + * The processed upload element. + */ + public function validateUploadElement(array $element, FormStateInterface $form_state) { + if ($form_state::hasAnyErrors()) { + // When an error occurs during uploading files, remove all files so the + // user can re-upload the files. + $element['#value'] = []; + } + $values = $form_state->getValue('upload', []); + if (count($values['uploaded_files']) > $element['#cardinality'] && $element['#cardinality'] !== FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) { + $form_state->setError($element, $this->t('A maximum of @count files can be uploaded.', [ + '@count' => $element['#cardinality'], + ])); + $form_state->setValue('upload', []); + $element['#value'] = []; + } + return $element; + } + + /** + * Submit handler for the upload button, inside the managed_file element. + * + * @param array $form + * The form render array. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state. + */ + public function uploadButtonSubmit(array $form, FormStateInterface $form_state) { + $files = $this->getFiles($form, $form_state); + $this->processInputValues($files, $form, $form_state); + } + + /** + * Gets uploaded files. + * + * We implement this to allow child classes to operate on different entity + * type while still having access to the files in the validate callback here. + * + * @param array $form + * Form structure. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * Form state object. + * + * @return \Drupal\file\FileInterface[] + * Array of uploaded files. + */ + protected function getFiles(array $form, FormStateInterface $form_state) { + // Create a file item to get the upload validators. + $media_type = $this->getMediaType($form_state); + $item = $this->createFileItem($media_type); + + $settings = $item->getFieldDefinition()->getSettings(); + + $additional_validators = ['file_validate_size' => [Bytes::toInt($settings['max_filesize']), 0]]; + + $files = $form_state->get(['dropzonejs', $this->getFormId(), 'files']); + + if (!$files) { + $files = []; + } + + // We do some casting because $form_state->getValue() might return NULL. + foreach ((array) $form_state->getValue(['upload', 'uploaded_files'], []) as $file) { + if (file_exists($file['path'])) { + $entity = $this->dropzoneJsUploadSave->createFile( + $file['path'], + // Need to leave destination empty, because Media Library will handle + // the moving of the file to proper location. + '', + $settings['file_extensions'], + $this->currentUser(), + $additional_validators + ); + if ($entity) { + $files[] = $entity; + } + } + } + + if ($form['container']['upload']['#max_files']) { + $files = array_slice($files, -$form['container']['upload']['#max_files']); + } + + $form_state->set(['dropzonejs', $this->getFormId(), 'files'], $files); + + return $files; + } + +} diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/dropzonejs_test.info.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/dropzonejs_test.info.yml index 4a269f227225c58ec1fe93c80dd3c1848cc515c6..0447d3ac19121f4533af38a3c3c08d0be5739335 100644 --- a/web/modules/dropzonejs/tests/modules/dropzonejs_test/dropzonejs_test.info.yml +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/dropzonejs_test.info.yml @@ -9,7 +9,7 @@ dependencies: - dropzonejs:dropzonejs - dropzonejs:dropzonejs_eb_widget -# Information added by Drupal.org packaging script on 2021-03-01 -version: '8.x-2.5' +# Information added by Drupal.org packaging script on 2022-03-21 +version: '8.x-2.6' project: 'dropzonejs' -datestamp: 1614606378 +datestamp: 1647857810