diff --git a/composer.json b/composer.json index e2306c605984ccd174b15bb62eed3f6c6f79c19f..7d8e05734155690c1ec6878e60d99830e0e943a8 100644 --- a/composer.json +++ b/composer.json @@ -110,7 +110,7 @@ "drupal/ctools": "3.2", "drupal/devel": "2.0", "drupal/draggableviews": "1.0", - "drupal/dropzonejs": "2.0-alpha3", + "drupal/dropzonejs": "2.1", "drupal/editor_advanced_link": "1.4", "drupal/embed": "1.0", "drupal/entity": "1.0-beta1", diff --git a/composer.lock b/composer.lock index ef69d35429675eb28f1aaddd4320821a48ed0b5b..0247108bf9c69fca640b7b6bed3aba46c8e782c8 100644 --- a/composer.lock +++ b/composer.lock @@ -4000,20 +4000,20 @@ }, { "name": "drupal/dropzonejs", - "version": "2.0.0-alpha3", + "version": "2.1.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/dropzonejs.git", - "reference": "8.x-2.0-alpha3" + "reference": "8.x-2.1" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/dropzonejs-8.x-2.0-alpha3.zip", - "reference": "8.x-2.0-alpha3", - "shasum": "a11f37e8f37b211d7065b0fd8adb1cc85b47e691" + "url": "https://ftp.drupal.org/files/projects/dropzonejs-8.x-2.1.zip", + "reference": "8.x-2.1", + "shasum": "a165b70070c320933fdce0c02be3577abce5e938" }, "require": { - "drupal/core": "*" + "drupal/core": "^8.8 || ^9" }, "require-dev": { "drupal/entity_browser": "*" @@ -4027,11 +4027,11 @@ "dev-2.x": "2.x-dev" }, "drupal": { - "version": "8.x-2.0-alpha3", - "datestamp": "1513265285", + "version": "8.x-2.1", + "datestamp": "1585662324", "security-coverage": { - "status": "not-covered", - "message": "Project has not opted into security advisory coverage!" + "status": "covered", + "message": "Covered by Drupal's security advisory policy" } } }, @@ -4087,9 +4087,9 @@ }, { "name": "drupal/dropzonejs_eb_widget", - "version": "2.0.0-alpha3", + "version": "2.1.0", "require": { - "drupal/core": "*", + "drupal/core": "^8.8 || ^9", "drupal/dropzonejs": "self.version", "drupal/entity_browser": "*" }, @@ -4099,11 +4099,11 @@ "dev-2.x": "2.x-dev" }, "drupal": { - "version": "8.x-2.0-alpha3", - "datestamp": "1513265285", + "version": "8.x-2.1", + "datestamp": "1585662324", "security-coverage": { - "status": "not-covered", - "message": "Project has not opted into security advisory coverage!" + "status": "covered", + "message": "Covered by Drupal's security advisory policy" } } }, @@ -4144,7 +4144,7 @@ "description": "DropzoneJS Entity browser widget", "homepage": "https://www.drupal.org/project/dropzonejs", "support": { - "source": "http://cgit.drupalcode.org/dropzonejs" + "source": "https://git.drupalcode.org/project/dropzonejs" } }, { diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 52ad9e97544c5d2902ab585ce14a33dc8c2a7f66..4aa7afa2521672a42b158ebddc5fee22c3c4200e 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -4120,21 +4120,21 @@ }, { "name": "drupal/dropzonejs", - "version": "2.0.0-alpha3", - "version_normalized": "2.0.0.0-alpha3", + "version": "2.1.0", + "version_normalized": "2.1.0.0", "source": { "type": "git", "url": "https://git.drupalcode.org/project/dropzonejs.git", - "reference": "8.x-2.0-alpha3" + "reference": "8.x-2.1" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/dropzonejs-8.x-2.0-alpha3.zip", - "reference": "8.x-2.0-alpha3", - "shasum": "a11f37e8f37b211d7065b0fd8adb1cc85b47e691" + "url": "https://ftp.drupal.org/files/projects/dropzonejs-8.x-2.1.zip", + "reference": "8.x-2.1", + "shasum": "a165b70070c320933fdce0c02be3577abce5e938" }, "require": { - "drupal/core": "*" + "drupal/core": "^8.8 || ^9" }, "require-dev": { "drupal/entity_browser": "*" @@ -4148,11 +4148,11 @@ "dev-2.x": "2.x-dev" }, "drupal": { - "version": "8.x-2.0-alpha3", - "datestamp": "1513265285", + "version": "8.x-2.1", + "datestamp": "1585662324", "security-coverage": { - "status": "not-covered", - "message": "Project has not opted into security advisory coverage!" + "status": "covered", + "message": "Covered by Drupal's security advisory policy" } } }, @@ -4209,10 +4209,10 @@ }, { "name": "drupal/dropzonejs_eb_widget", - "version": "2.0.0-alpha3", - "version_normalized": "2.0.0.0-alpha3", + "version": "2.1.0", + "version_normalized": "2.1.0.0", "require": { - "drupal/core": "*", + "drupal/core": "^8.8 || ^9", "drupal/dropzonejs": "self.version", "drupal/entity_browser": "*" }, @@ -4222,11 +4222,11 @@ "dev-2.x": "2.x-dev" }, "drupal": { - "version": "8.x-2.0-alpha3", - "datestamp": "1513265285", + "version": "8.x-2.1", + "datestamp": "1585662324", "security-coverage": { - "status": "not-covered", - "message": "Project has not opted into security advisory coverage!" + "status": "covered", + "message": "Covered by Drupal's security advisory policy" } } }, @@ -4267,7 +4267,7 @@ "description": "DropzoneJS Entity browser widget", "homepage": "https://www.drupal.org/project/dropzonejs", "support": { - "source": "http://cgit.drupalcode.org/dropzonejs" + "source": "https://git.drupalcode.org/project/dropzonejs" } }, { diff --git a/web/modules/dropzonejs/DEVELOPING.md b/web/modules/dropzonejs/DEVELOPING.md deleted file mode 100644 index 4f2113bec8058924761f99819cfe7a4c6857a974..0000000000000000000000000000000000000000 --- a/web/modules/dropzonejs/DEVELOPING.md +++ /dev/null @@ -1,3 +0,0 @@ -# Developing - -* Pull requests can be made against https://github.com/drupal-media/dropzonejs/pulls diff --git a/web/modules/dropzonejs/composer.json b/web/modules/dropzonejs/composer.json index d81649ef39da31c55e30fe082c684a67141734c9..975a82d2dc95dbb49194ec8009c85cc2e73cc268 100644 --- a/web/modules/dropzonejs/composer.json +++ b/web/modules/dropzonejs/composer.json @@ -34,8 +34,8 @@ "role": "contributor" } ], - "require": { - "enyo/dropzone": "^5.1" - }, - "suggest": {} + "require": {}, + "suggest": { + "enyo/dropzone": "Required to user drupal/dropzonejs. Dropzone is an easy to use drag'n'drop library." + } } diff --git a/web/modules/dropzonejs/composer.lock b/web/modules/dropzonejs/composer.lock deleted file mode 100644 index e9a267108ca0cf2e37dee31487e96bd80b517752..0000000000000000000000000000000000000000 --- a/web/modules/dropzonejs/composer.lock +++ /dev/null @@ -1,54 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "content-hash": "cccdd5e1084ad9bd1f718529877d861a", - "packages": [ - { - "name": "enyo/dropzone", - "version": "v5.1.1", - "source": { - "type": "git", - "url": "https://github.com/enyo/dropzone.git", - "reference": "7d0792d1346d83a8b0c0d2919121bdd2b8e7fee4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/enyo/dropzone/zipball/7d0792d1346d83a8b0c0d2919121bdd2b8e7fee4", - "reference": "7d0792d1346d83a8b0c0d2919121bdd2b8e7fee4", - "shasum": "" - }, - "type": "library", - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Matias Meno", - "email": "m@tias.me", - "homepage": "http://www.matiasmeno.com" - } - ], - "description": "Handles drag and drop of files for you.", - "homepage": "http://www.dropzonejs.com", - "keywords": [ - "drag and drop", - "dragndrop", - "file upload", - "upload" - ], - "time": "2017-06-20T13:39:37+00:00" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "dev", - "stability-flags": [], - "prefer-stable": true, - "prefer-lowest": false, - "platform": [], - "platform-dev": [] -} diff --git a/web/modules/dropzonejs/config/install/dropzonejs.settings.yml b/web/modules/dropzonejs/config/install/dropzonejs.settings.yml index 2bd019733090060b624e8c7c598855e45d136a89..940ac0d681af049e47bf5f0a4b8c14769a69df46 100644 --- a/web/modules/dropzonejs/config/install/dropzonejs.settings.yml +++ b/web/modules/dropzonejs/config/install/dropzonejs.settings.yml @@ -1 +1,2 @@ tmp_upload_scheme: temporary +filename_transliteration: true diff --git a/web/modules/dropzonejs/config/schema/dropzonejs.schema.yml b/web/modules/dropzonejs/config/schema/dropzonejs.schema.yml index 35eb9d7657154c9719b58fed621083fa5413f12e..ab7542039897c73659591b9d2d5c48e1a7f0f66e 100644 --- a/web/modules/dropzonejs/config/schema/dropzonejs.schema.yml +++ b/web/modules/dropzonejs/config/schema/dropzonejs.schema.yml @@ -5,3 +5,6 @@ dropzonejs.settings: tmp_upload_scheme: type: string label: 'Upload scheme' + filename_transliteration: + type: boolean + label: 'Transliterate names of uploaded files' diff --git a/web/modules/dropzonejs/dropzonejs.info.yml b/web/modules/dropzonejs/dropzonejs.info.yml index 1e3b766242fa11bb3b7feb06665b1b8767d1f018..e246dac93d992a737a7d5255869faaedf32263e4 100644 --- a/web/modules/dropzonejs/dropzonejs.info.yml +++ b/web/modules/dropzonejs/dropzonejs.info.yml @@ -1,13 +1,12 @@ name: dropzonejs type: module description: DropzoneJS -# core: 8.x +core_version_requirement: ^8.8 || ^9 package: Media dependencies: - - file + - drupal:file -# Information added by Drupal.org packaging script on 2017-12-14 -version: '8.x-2.0-alpha3' -core: '8.x' +# Information added by Drupal.org packaging script on 2020-03-31 +version: '8.x-2.1' project: 'dropzonejs' -datestamp: 1513265289 +datestamp: 1585662326 diff --git a/web/modules/dropzonejs/dropzonejs.install b/web/modules/dropzonejs/dropzonejs.install index 556faae4c1ee918e504f27910c6f23209cbcaf25..679b46c94174eed465a23568f451c8125d653b18 100644 --- a/web/modules/dropzonejs/dropzonejs.install +++ b/web/modules/dropzonejs/dropzonejs.install @@ -12,30 +12,40 @@ function dropzonejs_requirements($phase) { $requirements = []; - $path = DRUPAL_ROOT . '/libraries/dropzone/dist/min/dropzone.min.js'; - if (\Drupal::moduleHandler()->moduleExists('libraries')) { - $path = libraries_get_path('dropzone') . '/dist/min/dropzone.min.js'; + // @todo Remove this conditional structure in favor of using the libraries + // directory file finder service when Drupal 8.9 is the minimum supported + // version of core. + if (\Drupal::hasService('library.libraries_directory_file_finder')) { + /** @var \Drupal\Core\Asset\LibrariesDirectoryFileFinder $library_file_finder */ + $library_file_finder = \Drupal::service('library.libraries_directory_file_finder'); + $library_found = (bool) $library_file_finder->find('dropzone/dist/min/dropzone.min.js'); } + else { + $path = DRUPAL_ROOT . '/libraries/dropzone/dist/min/dropzone.min.js'; + if (\Drupal::moduleHandler()->moduleExists('libraries')) { + $path = libraries_get_path('dropzone') . '/dist/min/dropzone.min.js'; + } - // Is the library found in the root libraries path. - $library_found = file_exists($path); + // Is the library found in the root libraries path. + $library_found = file_exists($path); - // If library is not found, then look in the current profile libraries path. - if (!$library_found) { - $profile_path = drupal_get_path('profile', drupal_get_profile()); - $profile_path .= '/libraries/dropzone/dist/min/dropzone.min.js'; - // Is the library found in the current profile libraries path. - $library_found = file_exists($profile_path); + // If library is not found, then look in the current profile libraries path. + if (!$library_found) { + $profile_path = drupal_get_path('profile', \Drupal::installProfile()); + $profile_path .= '/libraries/dropzone/dist/min/dropzone.min.js'; + // Is the library found in the current profile libraries path. + $library_found = file_exists($profile_path); + } } if (!$library_found) { - $requirements['dropzonejs_library'] = array( + $requirements['dropzonejs_library'] = [ 'title' => t('Dropzone library missing'), 'description' => t('Dropzonejs requires the dropzone.min.js library. Download it (https://github.com/enyo/dropzone) and place it in the libraries folder (/libraries)'), 'severity' => REQUIREMENT_ERROR, - ); + ]; } return $requirements; @@ -51,3 +61,14 @@ function dropzonejs_update_8001() { $config->set('tmp_upload_scheme', 'temporary'); $config->save(TRUE); } + +/** + * Set default value for transliterate file name. + */ +function dropzonejs_update_8002() { + $config_factory = \Drupal::configFactory(); + $config = $config_factory->getEditable('dropzonejs.settings'); + $config->clear('filename_transliteration'); + $config->set('filename_transliteration', TRUE); + $config->save(TRUE); +} diff --git a/web/modules/dropzonejs/dropzonejs.module b/web/modules/dropzonejs/dropzonejs.module index 7f5120480d146c5a0511984bb647ec27f451eea2..7f44502ef50f30e32d5ea74a0dd33f1e73d7564c 100644 --- a/web/modules/dropzonejs/dropzonejs.module +++ b/web/modules/dropzonejs/dropzonejs.module @@ -65,14 +65,22 @@ function template_preprocess_dropzonejs(array &$variables) { function dropzonejs_library_info_build() { $libraries = []; - if (\Drupal::moduleHandler()->moduleExists('libraries')) { + // @todo Remove this conditional structure in favor of using the libraries + // directory file finder service when Drupal 8.9 is the minimum supported + // version of core. + if (\Drupal::hasService('library.libraries_directory_file_finder')) { + /** @var \Drupal\Core\Asset\LibrariesDirectoryFileFinder $library_file_finder */ + $library_file_finder = \Drupal::service('library.libraries_directory_file_finder'); + $exif_path = $library_file_finder->find('exif-js/exif.js'); + } + elseif (\Drupal::moduleHandler()->moduleExists('libraries')) { $exif_path = libraries_get_path('exif-js') . '/exif.js'; } else { $exif_path = DRUPAL_ROOT . '/libraries/exif-js/exif.js'; } - if ($exif_found = file_exists($exif_path)) { + if ($exif_path && file_exists($exif_path)) { $libraries['exif-js'] = [ 'title' => 'Exif', 'website' => 'https://github.com/exif-js/exif-js', diff --git a/web/modules/dropzonejs/dropzonejs.services.yml b/web/modules/dropzonejs/dropzonejs.services.yml index dd824658653e7ff4911cdcb6e2232f029ea0385f..107421e55e765c6e7ecf6ca240aa0ab7b3dca9ac 100644 --- a/web/modules/dropzonejs/dropzonejs.services.yml +++ b/web/modules/dropzonejs/dropzonejs.services.yml @@ -1,7 +1,7 @@ services: dropzonejs.upload_save: class: Drupal\dropzonejs\DropzoneJsUploadSave - arguments: ['@entity.manager', '@file.mime_type.guesser', '@file_system', '@logger.factory', '@renderer', '@config.factory', '@token'] + arguments: ['@entity_type.manager', '@file.mime_type.guesser', '@file_system', '@logger.factory', '@renderer', '@config.factory', '@token', '@messenger', '@stream_wrapper_manager'] dropzonejs.upload_handler: class: Drupal\dropzonejs\UploadHandler arguments: ['@request_stack', '@config.factory', '@transliteration', '@language_manager'] diff --git a/web/modules/dropzonejs/drupal_ti/.travis-phpcs.sh b/web/modules/dropzonejs/drupal_ti/.travis-phpcs.sh old mode 100644 new mode 100755 diff --git a/web/modules/dropzonejs/drupalci.yml b/web/modules/dropzonejs/drupalci.yml new file mode 100644 index 0000000000000000000000000000000000000000..6e6e229b36a172d76ac3ecb1ed57ebd5f58d4439 --- /dev/null +++ b/web/modules/dropzonejs/drupalci.yml @@ -0,0 +1,66 @@ +# This is the DrupalCI testbot build file for Drupal core. +# https://www.drupal.org/drupalorg/docs/drupal-ci/customizing-drupalci-testing +build: + assessment: + validate_codebase: + phplint: + csslint: + halt-on-fail: false + eslint: + # A test must pass eslinting standards check in order to continue processing. + halt-on-fail: false + phpcs: + # phpcs will use core's specified version of Coder. + sniff-all-files: false + halt-on-fail: false + testing: + container_command: + commands: + - "cd ${SOURCE_DIR}" + - "sudo -u www-data mkdir libraries" + - "sudo -u www-data curl https://codeload.github.com/enyo/dropzone/tar.gz/v5.5.0 --output dropzone.tar.gz --silent" + - "sudo -u www-data tar xzf dropzone.tar.gz" + - "sudo -u www-data mv dropzone-5.5.0 libraries/dropzone" + halt-on-fail: true + # run_tests task is executed several times in order of performance speeds. + # halt-on-fail can be set on the run_tests tasks in order to fail fast. + # suppress-deprecations is false in order to be alerted to usages of + # deprecated code. + run_tests.phpunit: + types: 'PHPUnit-Unit' + testgroups: '--all' + suppress-deprecations: true + halt-on-fail: false + run_tests.kernel: + types: 'PHPUnit-Kernel' + testgroups: '--all' + suppress-deprecations: true + halt-on-fail: false + run_tests.simpletest: + types: 'Simpletest' + testgroups: '--all' + suppress-deprecations: true + halt-on-fail: false + run_tests.build: + types: 'PHPUnit-Build' + testgroups: '--all' + suppress-deprecations: true + halt-on-fail: false + run_tests.functional: + types: 'PHPUnit-Functional' + testgroups: '--all' + suppress-deprecations: true + halt-on-fail: false + run_tests.javascript: + concurrency: 15 + types: 'PHPUnit-FunctionalJavascript' + testgroups: '--all' + suppress-deprecations: true + halt-on-fail: false + # Run nightwatch testing. + # @see https://www.drupal.org/project/drupal/issues/2869825 + nightwatchjs: +# container_command.drupal_project_templates: +# commands: +# - "sudo -u www-data ${SOURCE_DIR}/core/tests/scripts/test_composer_project_templates.sh" +# halt-on-fail: true diff --git a/web/modules/dropzonejs/js/dropzone.integration.js b/web/modules/dropzonejs/js/dropzone.integration.js index 38fd2528aa889015dda1bbc3ff50bd40de4608e9..14b1bd0ed2231b3035c20be339ccbbfe325ce4dd 100644 --- a/web/modules/dropzonejs/js/dropzone.integration.js +++ b/web/modules/dropzonejs/js/dropzone.integration.js @@ -15,82 +15,85 @@ attach: function (context) { Dropzone.autoDiscover = false; - // @todo Init functionality should support multiple drop zones on page. - var selector = $('.dropzone-enable'); - selector.addClass('dropzone'); - var input = selector.siblings('input'); - - // Initiate dropzonejs. - var config = { - url: input.attr('data-upload-path'), - addRemoveLinks: false - }; - var instanceConfig = drupalSettings.dropzonejs.instances[selector.attr('id')]; - - // If DropzoneJS instance is already registered on Element. There is no - // need to register it again. - if (selector.once('register-dropzonejs').length !== selector.length) { - return; - } - - // If instance exists for configuration, but it's detached from element - // then destroy detached instance and create new instance. - if (instanceConfig.instance !== void 0) { - instanceConfig.instance.destroy(); - } - - // Initialize DropzoneJS instance for element. - var dropzoneInstance = new Dropzone('#' + selector.attr('id'), $.extend({}, instanceConfig, config)); - - // Other modules might need instances. - drupalSettings['dropzonejs']['instances'][selector.attr('id')]['instance'] = dropzoneInstance; - - dropzoneInstance.on('addedfile', function (file) { - file._removeIcon = Dropzone.createElement("<div class='dropzonejs-remove-icon' title='Remove'></div>"); - file.previewElement.appendChild(file._removeIcon); - file._removeIcon.addEventListener('click', function () { - dropzoneInstance.removeFile(file); + $('.dropzone-enable').each(function() { + var selector = $(this); + selector.addClass('dropzone'); + + // selector.addClass('dropzone'); + var input = selector.siblings('input'); + + // Initiate dropzonejs. + var config = { + url: input.attr('data-upload-path'), + addRemoveLinks: false + }; + var instanceConfig = drupalSettings.dropzonejs.instances[selector.attr('id')]; + + // If DropzoneJS instance is already registered on Element. There is no + // need to register it again. + if (selector.once('register-dropzonejs').length !== selector.length) { + return; + } + + // If instance exists for configuration, but it's detached from element + // then destroy detached instance and create new instance. + if (instanceConfig.instance !== void 0) { + instanceConfig.instance.destroy(); + } + + // Initialize DropzoneJS instance for element. + var dropzoneInstance = new Dropzone('#' + selector.attr('id'), $.extend({}, instanceConfig, config)); + + // Other modules might need instances. + drupalSettings['dropzonejs']['instances'][selector.attr('id')]['instance'] = dropzoneInstance; + + dropzoneInstance.on('addedfile', function (file) { + file._removeIcon = Dropzone.createElement("<div class='dropzonejs-remove-icon' title='Remove'></div>"); + file.previewElement.appendChild(file._removeIcon); + file._removeIcon.addEventListener('click', function () { + dropzoneInstance.removeFile(file); + }); }); - }); - // React on add file. Add only accepted files. - dropzoneInstance.on('success', function (file, response) { - var uploadedFilesElement = selector.siblings(':hidden'); - var currentValue = uploadedFilesElement.attr('value') || ''; + // React on add file. Add only accepted files. + dropzoneInstance.on('success', function (file, response) { + var uploadedFilesElement = selector.siblings(':hidden'); + var currentValue = uploadedFilesElement.attr('value') || ''; - // The file is transliterated on upload. The element has to reflect - // the real filename. - file.processedName = response.result; + // The file is transliterated on upload. The element has to reflect + // the real filename. + file.processedName = response.result; - uploadedFilesElement.attr('value', currentValue + response.result + ';'); - }); + uploadedFilesElement.attr('value', currentValue + response.result + ';'); + }); - // React on file removing. - dropzoneInstance.on('removedfile', function (file) { - var uploadedFilesElement = selector.siblings(':hidden'); - var currentValue = uploadedFilesElement.attr('value'); - - // Remove the file from the element. - if (currentValue.length) { - var fileNames = currentValue.split(';'); - for (var i in fileNames) { - if (fileNames[i] === file.processedName) { - fileNames.splice(i, 1); - break; + // React on file removing. + dropzoneInstance.on('removedfile', function (file) { + var uploadedFilesElement = selector.siblings(':hidden'); + var currentValue = uploadedFilesElement.attr('value'); + + // Remove the file from the element. + if (currentValue.length) { + var fileNames = currentValue.split(';'); + for (var i in fileNames) { + if (fileNames[i] === file.processedName) { + fileNames.splice(i, 1); + break; + } } - } - var newValue = fileNames.join(';'); - uploadedFilesElement.attr('value', newValue); - } - }); + var newValue = fileNames.join(';'); + uploadedFilesElement.attr('value', newValue); + } + }); - // React on maxfilesexceeded. Remove all rejected files. - dropzoneInstance.on('maxfilesexceeded', function () { - var rejectedFiles = dropzoneInstance.getRejectedFiles(); - for (var i = 0; i < rejectedFiles.length; i++) { - dropzoneInstance.removeFile(rejectedFiles[i]); - } + // React on maxfilesexceeded. Remove all rejected files. + dropzoneInstance.on('maxfilesexceeded', function () { + var rejectedFiles = dropzoneInstance.getRejectedFiles(); + for (var i = 0; i < rejectedFiles.length; i++) { + dropzoneInstance.removeFile(rejectedFiles[i]); + } + }); }); } }; diff --git a/web/modules/dropzonejs/modules/eb_widget/config/schema/dropzonejs_eb_widget.schema.yml b/web/modules/dropzonejs/modules/eb_widget/config/schema/dropzonejs_eb_widget.schema.yml index ec9ec40890b8cf85db9bbe581b8397d05327ee2f..ad564f5d89a06f31de0e978594d7f59528e319fe 100644 --- a/web/modules/dropzonejs/modules/eb_widget/config/schema/dropzonejs_eb_widget.schema.yml +++ b/web/modules/dropzonejs/modules/eb_widget/config/schema/dropzonejs_eb_widget.schema.yml @@ -3,7 +3,7 @@ entity_browser.browser.widget.dropzonejs: label: 'DropzoneJS widget configuration' mapping: submit_text: - type: string + type: text label: 'Submit button text' auto_select: type: boolean @@ -12,7 +12,7 @@ entity_browser.browser.widget.dropzonejs: type: string label: 'Upload location' dropzone_description: - type: string + type: text label: 'Dropzone drag-n-drop zone text' max_filesize: type: string 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 6a7d9d9626c10b03698800fd19359ff9c7cffce8..c691dda5ffed3263991e1be8493d99544cc3b8f6 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 @@ -1,16 +1,15 @@ name: DropzoneJS entity browser widget type: module description: DropzoneJS Entity browser widget -# core: 8.x +core_version_requirement: ^8.8 || ^9 package: Media dependencies: - - file - - dropzonejs - - entity_browser + - drupal:file + - dropzonejs:dropzonejs + - entity_browser:entity_browser -# Information added by Drupal.org packaging script on 2017-12-14 -version: '8.x-2.0-alpha3' -core: '8.x' +# Information added by Drupal.org packaging script on 2020-03-31 +version: '8.x-2.1' project: 'dropzonejs' -datestamp: 1513265289 +datestamp: 1585662326 diff --git a/web/modules/dropzonejs/modules/eb_widget/dropzonejs_eb_widget.install b/web/modules/dropzonejs/modules/eb_widget/dropzonejs_eb_widget.install index 5323b773c3a17fe27e1776cde4392a801c6b9990..d3de4ef30ea85d0644aebb70ecf0e7b1062e3682 100644 --- a/web/modules/dropzonejs/modules/eb_widget/dropzonejs_eb_widget.install +++ b/web/modules/dropzonejs/modules/eb_widget/dropzonejs_eb_widget.install @@ -13,10 +13,12 @@ * Update hook dependencies. */ function dropzonejs_eb_widget_update_dependencies() { - $dependencies['dropzonejs_eb_widget'] = [ - 8202 => ['media_entity' => 8201], - ]; - return $dependencies; + if (\Drupal::moduleHandler()->moduleExists('media_entity')) { + $dependencies['dropzonejs_eb_widget'] = [ + 8202 => ['media_entity' => 8201], + ]; + return $dependencies; + } } /** 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 a12d95524558b2897b2e30cf78e6f15f5f3fdace..1b4b49b7912dc03df770c5dfb2586e27f354a223 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 @@ -3,18 +3,18 @@ namespace Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget; use Drupal\Component\Utility\Bytes; +use Drupal\Component\Utility\Environment; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\InvokeCommand; -use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\Utility\Token; use Drupal\dropzonejs\DropzoneJsUploadSaveInterface; use Drupal\entity_browser\WidgetBase; -use Drupal\entity_browser\WidgetValidationManager; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Drupal\Core\Asset\LibraryDiscoveryInterface; /** * Provides an Entity Browser widget that uploads new files. @@ -50,49 +50,81 @@ class DropzoneJsEbWidget extends WidgetBase { protected $token; /** - * Constructs widget plugin. + * The file system service. * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher - * Event dispatcher service. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager service. - * @param \Drupal\entity_browser\WidgetValidationManager $validation_manager - * The Widget Validation Manager service. - * @param \Drupal\dropzonejs\DropzoneJsUploadSaveInterface $dropzonejs_upload_save + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + + /** + * The library discovery service. + * + * @var \Drupal\Core\Asset\LibraryDiscoveryInterface + */ + protected $libraryDiscovery; + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + $widget = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $widget->setDropzoneJsUploadSave($container->get('dropzonejs.upload_save')); + $widget->setCurrentUser($container->get('current_user')); + $widget->setToken($container->get('token')); + $widget->setFileSystem($container->get('file_system')); + $widget->setLibraryDiscovery($container->get('library.discovery')); + + return $widget; + } + + /** + * Set the upload saving dropzonejs service. + * + * @param \Drupal\dropzonejs\DropzoneJsUploadSaveInterface $dropzoneJsUploadSave * The upload saving dropzonejs service. - * @param \Drupal\Core\Session\AccountProxyInterface $current_user + */ + protected function setDropzoneJsUploadSave(DropzoneJsUploadSaveInterface $dropzoneJsUploadSave) { + $this->dropzoneJsUploadSave = $dropzoneJsUploadSave; + } + + /** + * Set the current user service. + * + * @param \Drupal\Core\Session\AccountProxyInterface $currentUser * The current user service. + */ + protected function setCurrentUser(AccountProxyInterface $currentUser) { + $this->currentUser = $currentUser; + } + + /** + * Set the token service. + * * @param \Drupal\Core\Utility\Token $token * The token service. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EventDispatcherInterface $event_dispatcher, EntityTypeManagerInterface $entity_type_manager, WidgetValidationManager $validation_manager, DropzoneJsUploadSaveInterface $dropzonejs_upload_save, AccountProxyInterface $current_user, Token $token) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $event_dispatcher, $entity_type_manager, $validation_manager); - $this->dropzoneJsUploadSave = $dropzonejs_upload_save; - $this->currentUser = $current_user; + protected function setToken(Token $token) { $this->token = $token; } /** - * {@inheritdoc} + * Set the filesystem service. + * + * @param \Drupal\Core\File\FileSystemInterface $fileSystem + * The filesystem service. */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('event_dispatcher'), - $container->get('entity_type.manager'), - $container->get('plugin.manager.entity_browser.widget_validation'), - $container->get('dropzonejs.upload_save'), - $container->get('current_user'), - $container->get('token') - ); + protected function setFileSystem(FileSystemInterface $fileSystem) { + $this->fileSystem = $fileSystem; + } + + /** + * Set the Library Discovery service. + * + * @param \Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery + * The library discovery service. + */ + protected function setLibraryDiscovery(LibraryDiscoveryInterface $library_discovery) { + $this->libraryDiscovery = $library_discovery; } /** @@ -102,7 +134,7 @@ public function defaultConfiguration() { return [ 'upload_location' => 'public://[date:custom:Y]-[date:custom:m]', 'dropzone_description' => $this->t('Drop files here to upload them'), - 'max_filesize' => file_upload_max_size() / pow(Bytes::KILOBYTE, 2) . 'M', + 'max_filesize' => Environment::getUploadMaxSize() / pow(Bytes::KILOBYTE, 2) . 'M', 'extensions' => 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp', 'clientside_resize' => FALSE, 'resize_width' => NULL, @@ -213,7 +245,9 @@ protected function getFiles(array $form, FormStateInterface $form_state) { $this->currentUser, $additional_validators ); - $files[] = $entity; + if ($entity) { + $files[] = $entity; + } } } @@ -247,7 +281,7 @@ public function validate(array &$form, FormStateInterface $form_state) { // it's still better not to rely only on client side validation. if (($trigger['#type'] == 'submit' && $trigger['#name'] == 'op') || $trigger['#name'] === 'auto_select_handler') { $upload_location = $this->getUploadLocation(); - if (!file_prepare_directory($upload_location, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) { + if (!$this->fileSystem->prepareDirectory($upload_location, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS)) { $form_state->setError($form['widget']['upload'], $this->t('Files could not be uploaded because the destination directory %destination is not configured correctly.', ['%destination' => $this->getConfiguration()['settings']['upload_location']])); } @@ -376,7 +410,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta ]; - $exif_found = \Drupal::service('library.discovery')->getLibraryByName('dropzonejs', 'exif-js'); + $exif_found = $this->libraryDiscovery->getLibraryByName('dropzonejs', 'exif-js'); $form['clientside_resize'] = [ '#type' => 'checkbox', 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 94b4546fe255bdfe8557c1f04573798dc851d7ee..3e333f81a6fb9fab59943cbf3f89ecc57c2a4d1e 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 @@ -3,20 +3,13 @@ namespace Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget; use Drupal\Core\Entity\EntityDisplayRepositoryInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; -use Drupal\Core\Session\AccountProxyInterface; -use Drupal\Core\Utility\Token; -use Drupal\dropzonejs\DropzoneJsUploadSaveInterface; use Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent; use Drupal\dropzonejs\Events\Events; use Drupal\entity_browser\WidgetBase; -use Drupal\entity_browser\WidgetValidationManager; use Drupal\inline_entity_form\Element\InlineEntityForm; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Provides an Entity Browser widget that uploads and edit new files. @@ -38,52 +31,23 @@ class InlineEntityFormMediaWidget extends MediaEntityDropzoneJsEbWidget { protected $entityDisplayRepository; /** - * Constructs widget plugin. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher - * Event dispatcher service. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager service. - * @param \Drupal\entity_browser\WidgetValidationManager $validation_manager - * The Widget Validation Manager service. - * @param \Drupal\dropzonejs\DropzoneJsUploadSaveInterface $dropzonejs_upload_save - * The upload saving dropzonejs service. - * @param \Drupal\Core\Session\AccountProxyInterface $current_user - * The current user service. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler service. - * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository - * The entity display repository service. + * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EventDispatcherInterface $event_dispatcher, EntityTypeManagerInterface $entity_type_manager, WidgetValidationManager $validation_manager, DropzoneJsUploadSaveInterface $dropzonejs_upload_save, AccountProxyInterface $current_user, Token $token, ModuleHandlerInterface $module_handler, EntityDisplayRepositoryInterface $entity_display_repository) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $event_dispatcher, $entity_type_manager, $validation_manager, $dropzonejs_upload_save, $current_user, $token, $module_handler); + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + $widget = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $widget->setEntityDisplayRepository($container->get('entity_display.repository')); - $this->entityDisplayRepository = $entity_display_repository; + return $widget; } /** - * {@inheritdoc} + * Set the entity display repository service. + * + * @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entityDisplayRepository + * The entity display repository service. */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('event_dispatcher'), - $container->get('entity_type.manager'), - $container->get('plugin.manager.entity_browser.widget_validation'), - $container->get('dropzonejs.upload_save'), - $container->get('current_user'), - $container->get('token'), - $container->get('module_handler'), - $container->get('entity_display.repository') - ); + protected function setEntityDisplayRepository(EntityDisplayRepositoryInterface $entityDisplayRepository) { + $this->entityDisplayRepository = $entityDisplayRepository; } /** @@ -169,14 +133,18 @@ public function getForm(array &$original_form, FormStateInterface $form_state, a public function submitEdit(array $form, FormStateInterface $form_state) { $form_state->setRebuild(TRUE); - // Files have to saved before they can be viewed in the IEF form. $media_entities = $this->prepareEntities($form, $form_state); - $source_field = $this->getType()->getSource()->getSourceFieldDefinition($this->getType())->getName(); - foreach ($media_entities as $media_entity) { + foreach ($media_entities as $id => $media_entity) { /** @var \Drupal\file\Entity\File $file */ + // Files have to saved before they can be viewed in the IEF form. + $source_field = $this->getType()->getSource()->getSourceFieldDefinition($this->getType())->getName(); $file = $media_entity->$source_field->entity; $file->save(); $media_entity->$source_field->target_id = $file->id(); + + /** @var \Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent $event */ + $event = $this->eventDispatcher->dispatch(Events::MEDIA_ENTITY_PRECREATE, new DropzoneMediaEntityCreateEvent($media_entity, $file, $form, $form_state, $form)); + $media_entities[$id] = $event->getMediaEntity(); } $form_state->set('uploaded_entities', $media_entities); @@ -231,14 +199,15 @@ protected function prepareEntitiesFromForm(array $form, FormStateInterface $form */ public function submit(array &$element, array &$form, FormStateInterface $form_state) { $media_entities = $this->prepareEntitiesFromForm($form, $form_state); - $source_field = $this->getType()->getSource()->getSourceFieldDefinition($this->getType())->getName(); - foreach ($media_entities as $media_entity) { + foreach ($media_entities as $id => $media_entity) { + $source_field = $media_entity->getSource()->getConfiguration()['source_field']; $file = $media_entity->{$source_field}->entity; /** @var \Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent $event */ $event = $this->eventDispatcher->dispatch(Events::MEDIA_ENTITY_CREATE, new DropzoneMediaEntityCreateEvent($media_entity, $file, $form, $form_state, $element)); $media_entity = $event->getMediaEntity(); $media_entity->save(); + $media_entities[$id] = $media_entity; } if (!empty(array_filter($media_entities))) { 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 9e0083aff10f65189e6f2decd29fcbd1014d4ffe..34a12b09d0cee273a36b67db4bf4619a97727b53 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 @@ -2,18 +2,12 @@ namespace Drupal\dropzonejs_eb_widget\Plugin\EntityBrowser\Widget; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Link; -use Drupal\Core\Session\AccountProxyInterface; -use Drupal\Core\Utility\Token; -use Drupal\dropzonejs\DropzoneJsUploadSaveInterface; use Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent; use Drupal\dropzonejs\Events\Events; -use Drupal\entity_browser\WidgetValidationManager; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** * Provides an Entity Browser widget that uploads media entities. @@ -38,50 +32,23 @@ class MediaEntityDropzoneJsEbWidget extends DropzoneJsEbWidget { protected $moduleHandler; /** - * Constructs widget plugin. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher - * Event dispatcher service. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager service. - * @param \Drupal\entity_browser\WidgetValidationManager $validation_manager - * The Widget Validation Manager service. - * @param \Drupal\dropzonejs\DropzoneJsUploadSaveInterface $dropzonejs_upload_save - * The upload saving dropzonejs service. - * @param \Drupal\Core\Session\AccountProxyInterface $current_user - * The current user service. - * @param Token $token - * The token service. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler service. + * {@inheritdoc} */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, EventDispatcherInterface $event_dispatcher, EntityTypeManagerInterface $entity_type_manager, WidgetValidationManager $validation_manager, DropzoneJsUploadSaveInterface $dropzonejs_upload_save, AccountProxyInterface $current_user, Token $token, ModuleHandlerInterface $module_handler) { - parent::__construct($configuration, $plugin_id, $plugin_definition, $event_dispatcher, $entity_type_manager, $validation_manager, $dropzonejs_upload_save, $current_user, $token); - $this->moduleHandler = $module_handler; + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + $widget = parent::create($container, $configuration, $plugin_id, $plugin_definition); + $widget->setModuleHandler($container->get('module_handler')); + + return $widget; } /** - * {@inheritdoc} + * Set the module handler service. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler + * The module handler service. */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('event_dispatcher'), - $container->get('entity_type.manager'), - $container->get('plugin.manager.entity_browser.widget_validation'), - $container->get('dropzonejs.upload_save'), - $container->get('current_user'), - $container->get('token'), - $container->get('module_handler') - ); + protected function setModuleHandler(ModuleHandlerInterface $moduleHandler) { + $this->moduleHandler = $moduleHandler; } /** @@ -180,9 +147,9 @@ public function prepareEntities(array $form, FormStateInterface $form_state) { public function submit(array &$element, array &$form, FormStateInterface $form_state) { /** @var \Drupal\media\MediaInterface[] $media_entities */ $media_entities = $this->prepareEntities($form, $form_state); - $source_field = $this->getType()->getSource()->getConfiguration()['source_field']; - foreach ($media_entities as &$media_entity) { + foreach ($media_entities as $id => $media_entity) { + $source_field = $this->getType()->getSource()->getConfiguration()['source_field']; $file = $media_entity->$source_field->entity; /** @var \Drupal\dropzonejs\Events\DropzoneMediaEntityCreateEvent $event */ $event = $this->eventDispatcher->dispatch(Events::MEDIA_ENTITY_CREATE, new DropzoneMediaEntityCreateEvent($media_entity, $file, $form, $form_state, $element)); @@ -193,6 +160,7 @@ public function submit(array &$element, array &$form, FormStateInterface $form_s // in Media entity, but this workaround should work for now. $media_entity->$source_field->entity->save(); $media_entity->save(); + $media_entities[$id] = $media_entity; } $this->selectEntities($media_entities, $form_state); diff --git a/web/modules/dropzonejs/src/DropzoneJsUploadSave.php b/web/modules/dropzonejs/src/DropzoneJsUploadSave.php index a1a00e0963cebb80602caee0f7e8dca03213bcf9..99e1817889b647d72c0f36f8de10e95f2fcc3774 100644 --- a/web/modules/dropzonejs/src/DropzoneJsUploadSave.php +++ b/web/modules/dropzonejs/src/DropzoneJsUploadSave.php @@ -6,8 +6,10 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Logger\LoggerChannelFactoryInterface; +use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountProxyInterface; +use Drupal\Core\StreamWrapper\StreamWrapperManagerInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Utility\Token; use Drupal\file\FileInterface; @@ -73,6 +75,20 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface { */ protected $token; + /** + * The messenger service. + * + * @var \Drupal\Core\Messenger\MessengerInterface + */ + protected $messenger; + + /** + * The stream wrapper manager. + * + * @var \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface + */ + protected $streamWrapperManager; + /** * Construct the DropzoneUploadSave object. * @@ -90,8 +106,12 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface { * Config factory service. * @param \Drupal\Core\Utility\Token $token * The token service. + * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * The messenger service. + * @param \Drupal\Core\StreamWrapper\StreamWrapperManagerInterface $stream_wrapper_manager + * The stream wrapper manager. */ - public function __construct(EntityTypeManagerInterface $entity_type_manager, MimeTypeGuesserInterface $mimetype_guesser, FileSystemInterface $file_system, LoggerChannelFactoryInterface $logger_factory, RendererInterface $renderer, ConfigFactoryInterface $config_factory, Token $token) { + public function __construct(EntityTypeManagerInterface $entity_type_manager, MimeTypeGuesserInterface $mimetype_guesser, FileSystemInterface $file_system, LoggerChannelFactoryInterface $logger_factory, RendererInterface $renderer, ConfigFactoryInterface $config_factory, Token $token, MessengerInterface $messenger, StreamWrapperManagerInterface $stream_wrapper_manager) { $this->entityTypeManager = $entity_type_manager; $this->mimeTypeGuesser = $mimetype_guesser; $this->fileSystem = $file_system; @@ -99,6 +119,8 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Mim $this->renderer = $renderer; $this->configFactory = $config_factory; $this->token = $token; + $this->messenger = $messenger; + $this->streamWrapperManager = $stream_wrapper_manager; } /** @@ -106,7 +128,7 @@ public function __construct(EntityTypeManagerInterface $entity_type_manager, Mim */ public function createFile($uri, $destination, $extensions, AccountProxyInterface $user, array $validators = []) { // Create the file entity. - $uri = file_stream_wrapper_uri_normalize($uri); + $uri = $this->streamWrapperManager->normalizeUri($uri); $file_info = new \SplFileInfo($uri); /** @var \Drupal\file\FileInterface $file */ @@ -129,7 +151,7 @@ public function createFile($uri, $destination, $extensions, AccountProxyInterfac // to add it here or else the file upload will fail. if ($renamed && !empty($extensions)) { $extensions .= ' txt'; - drupal_set_message($this->t('For security reasons, your upload has been renamed to %filename.', ['%filename' => $file->getFilename()])); + $this->messenger->addMessage($this->t('For security reasons, your upload has been renamed to %filename.', ['%filename' => $file->getFilename()])); } // Validate the file. @@ -144,20 +166,21 @@ public function createFile($uri, $destination, $extensions, AccountProxyInterfac '#items' => $errors, ], ]; - drupal_set_message($this->renderer->renderPlain($message), 'error'); + $this->messenger->addError($this->renderer->renderPlain($message)); return FALSE; } // Prepare destination. if (!$this->prepareDestination($file, $destination)) { - drupal_set_message($this->t('The file could not be uploaded because the destination %destination is invalid.', ['%destination' => $destination]), 'error'); + $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 = file_unmanaged_move($uri, $file->getFileUri()); + $move_result = $this->fileSystem->move($uri, $file->getFileUri()); if (!$move_result) { - drupal_set_message($this->t('File upload error. Could not move uploaded file.'), 'error'); + $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; } @@ -217,8 +240,8 @@ protected function renameExecutableExtensions(FileInterface $file) { */ protected function prepareDestination(FileInterface $file, $destination) { // Assert that the destination contains a valid stream. - $destination_scheme = $this->fileSystem->uriScheme($destination); - if (!$this->fileSystem->validScheme($destination_scheme)) { + $destination_scheme = $this->streamWrapperManager::getScheme($destination); + if (!$this->streamWrapperManager->isValidScheme($destination_scheme)) { return FALSE; } @@ -231,7 +254,7 @@ protected function prepareDestination(FileInterface $file, $destination) { if (substr($destination, -1) != '/') { $destination .= '/'; } - $destination = file_destination($destination . $file->getFilename(), FILE_EXISTS_RENAME); + $destination = $this->fileSystem->getDestinationFilename($destination . $file->getFilename(), FileSystemInterface::EXISTS_RENAME); $file->setFileUri($destination); return TRUE; } diff --git a/web/modules/dropzonejs/src/Element/DropzoneJs.php b/web/modules/dropzonejs/src/Element/DropzoneJs.php index ead6be03830f7a669365b02381e21f3fe2e05f09..11aedb1c3b12b8ea00c89676a29d8d1cff42955f 100644 --- a/web/modules/dropzonejs/src/Element/DropzoneJs.php +++ b/web/modules/dropzonejs/src/Element/DropzoneJs.php @@ -3,6 +3,7 @@ namespace Drupal\dropzonejs\Element; use Drupal\Component\Utility\Bytes; +use Drupal\Component\Utility\Environment; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Form\FormStateInterface; @@ -96,7 +97,7 @@ public static function processDropzoneJs(&$element, FormStateInterface $form_sta ]; if (empty($element['#max_filesize'])) { - $element['#max_filesize'] = file_upload_max_size(); + $element['#max_filesize'] = Environment::getUploadMaxSize(); } // Set #max_files to NULL (explicitly unlimited) if #max_files is not @@ -107,7 +108,7 @@ public static function processDropzoneJs(&$element, FormStateInterface $form_sta if (!\Drupal::currentUser()->hasPermission('dropzone upload files')) { $element['#access'] = FALSE; - drupal_set_message(new TranslatableMarkup("You don't have sufficent permissions to use the DropzoneJS uploader. Contact your system administrator"), 'warning'); + \Drupal::messenger()->addWarning(new TranslatableMarkup("You don't have sufficent permissions to use the DropzoneJS uploader. Contact your system administrator")); } return $element; @@ -185,7 +186,9 @@ public static function valueCallback(&$element, $input, FormStateInterface $form if (file_exists($old_filepath)) { // Finaly rename the file and add it to results. $new_filepath = $tmp_upload_scheme . '://' . $name; - $move_result = file_unmanaged_move($old_filepath, $new_filepath); + /** @var \Drupal\Core\File\FileSystemInterface $file_system */ + $file_system = \Drupal::service('file_system'); + $move_result = $file_system->move($old_filepath, $new_filepath); if ($move_result) { $return['uploaded_files'][] = [ @@ -194,7 +197,7 @@ public static function valueCallback(&$element, $input, FormStateInterface $form ]; } else { - drupal_set_message(self::t('There was a problem while processing the file named @name', ['@name' => $name]), 'error'); + \Drupal::messenger()->addError(self::t('There was a problem while processing the file named @name', ['@name' => $name])); } } } diff --git a/web/modules/dropzonejs/src/Events/Events.php b/web/modules/dropzonejs/src/Events/Events.php index 7a0a2e50f8a9492dcbdb31b12991c0b9907dc3d5..17800db5e9d870fb1c0bf8e4d48ea79b8152fb56 100644 --- a/web/modules/dropzonejs/src/Events/Events.php +++ b/web/modules/dropzonejs/src/Events/Events.php @@ -17,4 +17,15 @@ final class Events { */ const MEDIA_ENTITY_CREATE = 'dropzonejs.media_entity_create'; + /** + * The MEDIA_ENTITY_PRECREATE event. + * + * This event occurs when creating a new Media Entity, + * before it is displayed in the Inline Entity Form Widget (currently only + * used there) + * + * @var string + */ + const MEDIA_ENTITY_PRECREATE = 'dropzonejs.media_entity_precreate'; + } diff --git a/web/modules/dropzonejs/src/UploadException.php b/web/modules/dropzonejs/src/UploadException.php index b1d3b95b806156c0519eeb720fbb802accc1f738..bb5a53339dd8c94af3e0459859adb3dfec98ed7a 100644 --- a/web/modules/dropzonejs/src/UploadException.php +++ b/web/modules/dropzonejs/src/UploadException.php @@ -44,14 +44,14 @@ class UploadException extends \Exception { * * @var array */ - public $errorMessages = array( + public $errorMessages = [ self::INPUT_ERROR => 'Failed to open input stream.', self::OUTPUT_ERROR => 'Failed to open output stream.', self::MOVE_ERROR => 'Failed to move uploaded file.', self::DESTINATION_FOLDER_ERROR => 'Failed to open temporary directory for write.', self::FILENAME_ERROR => 'Invalid temporary file name.', self::FILE_UPLOAD_ERROR => 'The file upload resulted in an error on php level. See http://php.net/manual/en/features.file-upload.errors.php', - ); + ]; /** * Constructs UploadException. @@ -74,11 +74,11 @@ public function __construct($code, $message = NULL) { */ public function getErrorResponse() { return new JsonResponse( - array( + [ 'jsonrpc' => '2.0', 'error' => $this->errorMessages[$this->code], 'id' => 'id', - ), + ], 500 ); } diff --git a/web/modules/dropzonejs/src/UploadHandler.php b/web/modules/dropzonejs/src/UploadHandler.php index cc4d4c278f4b14be2dd548560dee1f9c5ba65e59..093845ee0f4c71ced9383dccc6ad606eb4001c31 100644 --- a/web/modules/dropzonejs/src/UploadHandler.php +++ b/web/modules/dropzonejs/src/UploadHandler.php @@ -8,7 +8,6 @@ use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\RequestStack; -use Drupal\Component\Utility\Unicode; /** * Handles files uploaded by Dropzone. @@ -45,11 +44,11 @@ class UploadHandler implements UploadHandlerInterface { protected $languageManager; /** - * The scheme (stream wrapper) used to store uploaded files. + * The settings of dropzonejs. * - * @var string + * @var \Drupal\Core\Config\ImmutableConfig */ - protected $tmpUploadScheme; + protected $dropzoneSettings; /** * Constructs dropzone upload controller route controller. @@ -67,7 +66,7 @@ public function __construct(RequestStack $request_stack, ConfigFactoryInterface $this->request = $request_stack->getCurrentRequest(); $this->transliteration = $transliteration; $this->languageManager = $language_manager; - $this->tmpUploadScheme = $config_factory->get('dropzonejs.settings')->get('tmp_upload_scheme'); + $this->dropzoneSettings = $config_factory->get('dropzonejs.settings'); } /** @@ -82,6 +81,10 @@ public function getFilename(UploadedFile $file) { throw new UploadException(UploadException::FILENAME_ERROR); } + if (!$this->dropzoneSettings->get('filename_transliteration')) { + return $original_name . '.txt'; + } + // @todo The following filename sanitization steps replicate the behaviour // of the 2492171-28 patch for https://www.drupal.org/node/2492171. // Try to reuse that code instead, once that issue is committed. @@ -96,14 +99,12 @@ public function getFilename(UploadedFile $file) { // Remove multiple consecutive non-alphabetical characters. $filename = preg_replace('/(_)_+|(\.)\.+|(-)-+/', '\\1\\2\\3', $filename); // Force lowercase to prevent issues on case-insensitive file systems. - $filename = Unicode::strtolower($filename); + $filename = strtolower($filename); // For security reasons append the txt extension. It will be removed in // Drupal\dropzonejs\Element::valueCallback when we will know the valid // extension and we will be able to properly sanitize the filename. - $processed_filename = $filename . '.txt'; - - return $processed_filename; + return $filename . '.txt'; } /** @@ -120,24 +121,24 @@ public function handleUpload(UploadedFile $file) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: $message = $this->t('The file could not be saved because it exceeds the maximum allowed size for uploads.'); - continue; + break; case UPLOAD_ERR_PARTIAL: case UPLOAD_ERR_NO_FILE: $message = $this->t('The file could not be saved because the upload did not complete.'); - continue; + break; // Unknown error. default: $message = $this->t('The file could not be saved. An unknown error has occurred.'); - continue; + break; } throw new UploadException(UploadException::FILE_UPLOAD_ERROR, $message); } // Open temp file. - $tmp = $this->tmpUploadScheme . '://' . $this->getFilename($file); + $tmp = $this->dropzoneSettings->get('tmp_upload_scheme') . '://' . $this->getFilename($file); if (!($out = fopen($tmp, $this->request->request->get('chunk', 0) ? 'ab' : 'wb'))) { throw new UploadException(UploadException::OUTPUT_ERROR); } diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_form_display.media.dropzonejs_media.default.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_form_display.media.dropzonejs_media.default.yml new file mode 100644 index 0000000000000000000000000000000000000000..b0e502580c44c528e085e7738120fa8bd801b33f --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_form_display.media.dropzonejs_media.default.yml @@ -0,0 +1,61 @@ +langcode: en +status: true +dependencies: + config: + - field.field.media.dropzonejs_media.field_media_image + - image.style.thumbnail + - media.type.dropzonejs_media + module: + - image + - path +id: media.dropzonejs_media.default +targetEntityType: media +bundle: dropzonejs_media +mode: default +content: + created: + type: datetime_timestamp + weight: 10 + region: content + settings: { } + third_party_settings: { } + field_media_image: + weight: 0 + settings: + progress_indicator: throbber + preview_image_style: thumbnail + third_party_settings: { } + type: image_image + region: content + name: + type: string_textfield + weight: -5 + region: content + settings: + size: 60 + placeholder: '' + third_party_settings: { } + path: + type: path + weight: 30 + region: content + settings: { } + third_party_settings: { } + status: + type: boolean_checkbox + settings: + display_label: true + weight: 100 + region: content + third_party_settings: { } + uid: + type: entity_reference_autocomplete + weight: 5 + settings: + match_operator: CONTAINS + size: 60 + placeholder: '' + match_limit: 10 + region: content + third_party_settings: { } +hidden: { } diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_form_display.node.dropzonejs_test.default.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_form_display.node.dropzonejs_test.default.yml new file mode 100644 index 0000000000000000000000000000000000000000..0cb4bbb2be7c757771a82edac717f15676353664 --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_form_display.node.dropzonejs_test.default.yml @@ -0,0 +1,82 @@ +uuid: cc12d4b9-9cb9-43d3-b92a-b6106b6df5f1 +langcode: en +status: true +dependencies: + config: + - entity_browser.browser.dropzonejs_eb_test + - field.field.node.dropzonejs_test.field_dropzonejs_image + - node.type.dropzonejs_test + module: + - entity_browser + - path +id: node.dropzonejs_test.default +targetEntityType: node +bundle: dropzonejs_test +mode: default +content: + created: + type: datetime_timestamp + weight: 3 + region: content + settings: { } + third_party_settings: { } + field_dropzonejs_image: + weight: 1 + settings: + entity_browser: dropzonejs_eb_test + field_widget_display: label + open: true + selection_mode: selection_append + field_widget_edit: false + field_widget_remove: false + field_widget_replace: false + field_widget_display_settings: { } + third_party_settings: { } + type: entity_browser_entity_reference + region: content + path: + type: path + weight: 6 + region: content + settings: { } + third_party_settings: { } + promote: + type: boolean_checkbox + settings: + display_label: true + weight: 4 + region: content + third_party_settings: { } + status: + type: boolean_checkbox + settings: + display_label: true + weight: 7 + region: content + third_party_settings: { } + sticky: + type: boolean_checkbox + settings: + display_label: true + weight: 5 + region: content + third_party_settings: { } + title: + type: string_textfield + weight: 0 + region: content + settings: + size: 60 + placeholder: '' + third_party_settings: { } + uid: + type: entity_reference_autocomplete + weight: 2 + settings: + match_operator: CONTAINS + size: 60 + placeholder: '' + match_limit: 10 + region: content + third_party_settings: { } +hidden: { } diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_view_display.media.dropzonejs_media.default.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_view_display.media.dropzonejs_media.default.yml new file mode 100644 index 0000000000000000000000000000000000000000..f0e3d5414611770ce88f2ffb8559e9daa013b656 --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_view_display.media.dropzonejs_media.default.yml @@ -0,0 +1,28 @@ +langcode: en +status: true +dependencies: + config: + - field.field.media.dropzonejs_media.field_media_image + - image.style.large + - media.type.dropzonejs_media + module: + - image +id: media.dropzonejs_media.default +targetEntityType: media +bundle: dropzonejs_media +mode: default +content: + field_media_image: + label: visually_hidden + weight: 0 + settings: + image_style: large + image_link: '' + third_party_settings: { } + type: image + region: content +hidden: + created: true + name: true + thumbnail: true + uid: true diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_view_display.node.dropzonejs_test.default.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_view_display.node.dropzonejs_test.default.yml new file mode 100644 index 0000000000000000000000000000000000000000..262458c14d46ff43f4d0a8c066ae8feb42020a32 --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/core.entity_view_display.node.dropzonejs_test.default.yml @@ -0,0 +1,28 @@ +langcode: en +status: true +dependencies: + config: + - field.field.node.dropzonejs_test.field_dropzonejs_image + - node.type.dropzonejs_test + module: + - user +id: node.dropzonejs_test.default +targetEntityType: node +bundle: dropzonejs_test +mode: default +content: + field_dropzonejs_image: + type: entity_reference_entity_view + weight: 101 + label: above + settings: + view_mode: default + link: false + third_party_settings: { } + region: content + links: + weight: 100 + settings: { } + third_party_settings: { } + region: content +hidden: { } diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/entity_browser.browser.dropzonejs_eb_test.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/entity_browser.browser.dropzonejs_eb_test.yml new file mode 100644 index 0000000000000000000000000000000000000000..8c0fd40a0bc2fbc450b487331692f848f73f1dd5 --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/entity_browser.browser.dropzonejs_eb_test.yml @@ -0,0 +1,40 @@ +langcode: en +status: true +dependencies: + config: + - media.type.dropzonejs_media + module: + - dropzonejs_eb_widget + - media +name: dropzonejs_eb_test +label: 'Dropzonejs eb test' +display: iframe +display_configuration: + width: '650' + height: '500' + link_text: 'Select entities' + auto_open: false +selection_display: no_display +selection_display_configuration: { } +widget_selector: single +widget_selector_configuration: { } +widgets: + 44b1e6ea-637d-4dd6-b79e-edeefc546c1c: + settings: + media_type: dropzonejs_media + upload_location: 'public://' + dropzone_description: 'Drop files here to upload them' + max_filesize: 2M + extensions: 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp' + clientside_resize: false + resize_width: null + resize_height: null + resize_quality: !!float 1 + resize_method: contain + thumbnail_method: contain + submit_text: 'Select entities' + auto_select: false + uuid: 44b1e6ea-637d-4dd6-b79e-edeefc546c1c + weight: 2 + label: 'Dropzonejs media' + id: dropzonejs_media_entity diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.field.media.dropzonejs_media.field_media_image.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.field.media.dropzonejs_media.field_media_image.yml new file mode 100644 index 0000000000000000000000000000000000000000..5ba3280d9e5f229e857e052dc7a6a16f326ca725 --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.field.media.dropzonejs_media.field_media_image.yml @@ -0,0 +1,37 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.media.field_media_image + - media.type.dropzonejs_media + module: + - image +id: media.dropzonejs_media.field_media_image +field_name: field_media_image +entity_type: media +bundle: dropzonejs_media +label: Image +description: '' +required: true +translatable: true +default_value: { } +default_value_callback: '' +settings: + file_extensions: 'png gif jpg jpeg' + alt_field: true + alt_field_required: true + title_field: false + title_field_required: false + max_resolution: '' + min_resolution: '' + default_image: + uuid: null + alt: '' + title: '' + width: null + height: null + file_directory: '[date:custom:Y]-[date:custom:m]' + max_filesize: '' + handler: 'default:file' + handler_settings: { } +field_type: image diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.field.node.dropzonejs_test.field_dropzonejs_image.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.field.node.dropzonejs_test.field_dropzonejs_image.yml new file mode 100644 index 0000000000000000000000000000000000000000..dc2e5f3de4895ef0135f39b04546c67a27cb8e84 --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.field.node.dropzonejs_test.field_dropzonejs_image.yml @@ -0,0 +1,27 @@ +langcode: en +status: true +dependencies: + config: + - field.storage.node.field_dropzonejs_image + - media.type.dropzonejs_media + - node.type.dropzonejs_test +id: node.dropzonejs_test.field_dropzonejs_image +field_name: field_dropzonejs_image +entity_type: node +bundle: dropzonejs_test +label: Image +description: '' +required: false +translatable: false +default_value: { } +default_value_callback: '' +settings: + handler: 'default:media' + handler_settings: + target_bundles: + dropzonejs_media: dropzonejs_media + sort: + field: _none + auto_create: false + auto_create_bundle: '' +field_type: entity_reference diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.storage.media.field_media_image.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.storage.media.field_media_image.yml new file mode 100644 index 0000000000000000000000000000000000000000..12387fdc48508ac6430fbddb53902860ba90f08e --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.storage.media.field_media_image.yml @@ -0,0 +1,34 @@ +langcode: en +status: true +dependencies: + enforced: + module: + - media + module: + - file + - image + - media +_core: + default_config_hash: 7ZBrcl87ZXaw42v952wwcw_9cQgTBq5_5tgyUkE-VV0 +id: media.field_media_image +field_name: field_media_image +entity_type: media +type: image +settings: + default_image: + uuid: null + alt: '' + title: '' + width: null + height: null + target_type: file + display_field: false + display_default: false + uri_scheme: public +module: image +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.storage.node.field_dropzonejs_image.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.storage.node.field_dropzonejs_image.yml new file mode 100644 index 0000000000000000000000000000000000000000..3844f35bc9289cedb451de9b698e2af1868898bf --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/field.storage.node.field_dropzonejs_image.yml @@ -0,0 +1,19 @@ +langcode: en +status: true +dependencies: + module: + - media + - node +id: node.field_dropzonejs_image +field_name: field_dropzonejs_image +entity_type: node +type: entity_reference +settings: + target_type: media +module: core +locked: false +cardinality: 1 +translatable: true +indexes: { } +persist_with_no_fields: false +custom_storage: false diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/media.type.dropzonejs_media.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/media.type.dropzonejs_media.yml new file mode 100644 index 0000000000000000000000000000000000000000..101afe31d612fcb45c6d8a5b1392ca51d290d88f --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/media.type.dropzonejs_media.yml @@ -0,0 +1,12 @@ +langcode: en +status: true +dependencies: { } +id: dropzonejs_media +label: 'Dropzonejs media' +description: '' +source: image +queue_thumbnail_downloads: false +new_revision: false +source_configuration: + source_field: field_media_image +field_map: { } diff --git a/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/node.type.dropzonejs_test.yml b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/node.type.dropzonejs_test.yml new file mode 100644 index 0000000000000000000000000000000000000000..fc9cbb69c5745b5bc08f3160f35abf57c537fa93 --- /dev/null +++ b/web/modules/dropzonejs/tests/modules/dropzonejs_test/config/install/node.type.dropzonejs_test.yml @@ -0,0 +1,16 @@ +langcode: en +status: true +dependencies: + module: + - menu_ui +third_party_settings: + menu_ui: + available_menus: { } + parent: '' +name: 'Dropzonejs test' +type: dropzonejs_test +description: '' +help: '' +new_revision: false +preview_mode: 0 +display_submitted: false 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 241623c6ea84f16f11483ae8cc62f3d2445ec5d5..ba9f5b3259dc9e0edc2c7fbbe8a96047962ef9a0 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 @@ -3,12 +3,12 @@ type: module description: 'Support module for DropzoneJs tests.' package: Testing # version: VERSION -# core: 8.x dependencies: - - dropzonejs + - drupal:media + - dropzonejs:dropzonejs + - dropzonejs:dropzonejs_eb_widget -# Information added by Drupal.org packaging script on 2017-12-14 -version: '8.x-2.0-alpha3' -core: '8.x' +# Information added by Drupal.org packaging script on 2020-03-31 +version: '8.x-2.1' project: 'dropzonejs' -datestamp: 1513265289 +datestamp: 1585662326 diff --git a/web/modules/dropzonejs/tests/src/FunctionalJavascript/DropzoneJsEbWidgetTest.php b/web/modules/dropzonejs/tests/src/FunctionalJavascript/DropzoneJsEbWidgetTest.php new file mode 100644 index 0000000000000000000000000000000000000000..504cb19137fb05f49f736e28d7ddbdfca1966869 --- /dev/null +++ b/web/modules/dropzonejs/tests/src/FunctionalJavascript/DropzoneJsEbWidgetTest.php @@ -0,0 +1,70 @@ +<?php + +namespace Drupal\Tests\dropzonejs\FunctionalJavascript; + +use Drupal\Tests\field_ui\Traits\FieldUiTestTrait; + +/** + * Test dropzonejs EB Widget. + * + * @group dropzonejs + */ +class DropzoneJsEbWidgetTest extends DropzoneJsWebDriverTestBase { + + use FieldUiTestTrait; + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = [ + 'node', + 'media', + 'menu_ui', + 'path', + 'dropzonejs_test', + ]; + + /** + * Permissions for user that will be logged-in for test. + * + * @var array + */ + protected static $userPermissions = [ + 'access dropzonejs_eb_test entity browser pages', + 'create dropzonejs_test content', + 'dropzone upload files', + 'access content', + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $account = $this->drupalCreateUser(static::$userPermissions); + $this->drupalLogin($account); + } + + /** + * Tests the add widget with iframe form. + */ + public function testUploadFile() { + $this->drupalGet('node/add/dropzonejs_test'); + $this->getSession()->getPage()->clickLink('Select entities'); + $this->waitForAjaxToFinish(); + $this->getSession()->switchToIFrame('entity_browser_iframe_dropzonejs_eb_test'); + $this->dropFile(); + $this->waitForAjaxToFinish(); + $this->getSession()->getPage()->pressButton('Select entities'); + + // Switch back to the main page. + $this->getSession()->switchToIFrame(); + $this->waitForAjaxToFinish(); + // For some reason we have to wait here for the markup to show up regardless + // of the waitForAjaxToFinish above. + sleep(2); + $this->assertSession()->elementContains('xpath', '//div[contains(@class, "entities-list")]/div[contains(@class, "label")]', 'notalama.jpg'); + } +} diff --git a/web/modules/dropzonejs/tests/src/FunctionalJavascript/DropzoneJsWebDriverTestBase.php b/web/modules/dropzonejs/tests/src/FunctionalJavascript/DropzoneJsWebDriverTestBase.php new file mode 100644 index 0000000000000000000000000000000000000000..0a858b09dd0cf418aae1f8701033e74750675b6c --- /dev/null +++ b/web/modules/dropzonejs/tests/src/FunctionalJavascript/DropzoneJsWebDriverTestBase.php @@ -0,0 +1,117 @@ +<?php + +namespace Drupal\Tests\dropzonejs\FunctionalJavascript; + +use Drupal\file\Entity\File; +use Drupal\FunctionalJavascriptTests\WebDriverTestBase; + +/** + * Base class for DropzoneJS Web driver functional test base. + * + * @package Drupal\Tests\entity_browser\FunctionalJavascript + */ +abstract class DropzoneJsWebDriverTestBase extends WebDriverTestBase { + + protected $defaultTheme = 'classy'; + + /** + * Simple grey rectangle image data. + * + * @var string + */ + var $fileData = "iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAAAAABVicqIAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA +B3RJTUUH3gIYBAEMHCkuWQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUH +AAAAQElEQVRo3u3NQQ0AAAgEoNN29i9kCh9uUICa3OtIJBKJRCKRSCQSiUQikUgkEolEIpFIJBKJ +RCKRSCQSiUTyPlnSFQER9VCp/AAAAABJRU5ErkJggg=="; + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = [ + 'dropzonejs_test', + 'views', + 'block', + 'node', + 'file', + 'image', + 'field_ui', + 'views_ui', + 'system', + ]; + + /** + * Creates an file. + * + * @param string $name + * The name of the image. + * @param string $extension + * File extension. + * + * @return \Drupal\file\FileInterface + * Returns an image. + * @throws \Drupal\Core\Entity\EntityStorageException + */ + protected function getFile($name, $extension = 'jpg') { + file_put_contents('public://' . $name . '.' . $extension, $this->fileData); + + $file = File::create([ + 'filename' => $name . '.' . $extension, + 'uri' => 'public://' . $name . '.' . $extension, + ]); + $file->setPermanent(); + $file->save(); + + return $file; + } + + /** + * Waits for jQuery to become ready and animations to complete. + */ + protected function waitForAjaxToFinish() { + $this->assertSession()->assertWaitOnAjaxRequest(); + } + + /** + * Drop a predefined file to dropzone. + * + * @throws \Behat\Mink\Exception\ElementNotFoundException + * @throws \Drupal\Core\Entity\EntityStorageException + */ + protected function dropFile() { + // Sometimes we are not yet switched to the iframe. Stop the horses a bit + // here. + sleep(1); + $file = $this->getFile('notalama'); + + $input = <<<JS + jQuery('.form-type-dropzonejs').append('<input type=\'file\' name=\'fakefile\'>'); +JS; + $this->getSession()->evaluateScript($input); + + $full_path = \Drupal::service('file_system')->realPath($file->getFileUri()); + if (is_file($full_path)) { + $path = $full_path; + } + + if (!isset($path) || !file_exists($path)) { + throw new \RuntimeException("File $path does not exist"); + } + + $this->getSession()->getPage()->attachFileToField('fakefile', $path); + + $drop = <<<JS + (function(jQuery) { + var fakeFileInputs = jQuery('input[name=fakefile]' ); + var fileList = fakeFileInputs.map(function (i, el) { return el.files[0] }); + var e = jQuery.Event('drop', { dataTransfer : { files : fileList } }); + jQuery('.dropzone' )[0].dropzone.listeners[0].events.drop(e); + fakeFileInputs.map(function (i, el) { return el.remove(); }); + })(jQuery); +JS; + + $this->getSession()->evaluateScript($drop); + } + +} diff --git a/web/modules/dropzonejs/tests/src/Kernel/DropzoneJsElementTest.php b/web/modules/dropzonejs/tests/src/Kernel/DropzoneJsElementTest.php index 9711c6c8bba404e0245e1a49ab821db2ed672bce..7a8e55482ccbf8c8585d643c43325e326b12ee77 100644 --- a/web/modules/dropzonejs/tests/src/Kernel/DropzoneJsElementTest.php +++ b/web/modules/dropzonejs/tests/src/Kernel/DropzoneJsElementTest.php @@ -31,7 +31,6 @@ class DropzoneJsElementTest extends KernelTestBase { */ protected function setUp() { parent::setUp(); - $this->installSchema('system', 'router'); $this->installEntitySchema('user'); /** @var \Drupal\user\RoleInterface $role */ @@ -50,17 +49,17 @@ public function testDropzoneJsElement() { $xpath_base = "//div[contains(@class, 'form-item-dropzonejs')]"; // Label. - $this->assertFalse($this->xpath("$xpath_base/label[text()='Not DropzoneJs element']")); - $this->assertTrue($this->xpath("$xpath_base/label[text()='DropzoneJs element']")); + $this->assertEmpty($this->xpath("$xpath_base/label[text()='Not DropzoneJs element']")); + $this->assertNotEmpty($this->xpath("$xpath_base/label[text()='DropzoneJs element']")); // Element where dropzonejs is attached to. - $this->assertTrue($this->xpath("$xpath_base/div[contains(@class, 'dropzone-enable')]")); + $this->assertNotEmpty($this->xpath("$xpath_base/div[contains(@class, 'dropzone-enable')]")); // Uploaded files input. - $this->assertTrue($this->xpath("$xpath_base/input[contains(@data-drupal-selector, 'edit-dropzonejs-uploaded-files')]")); + $this->assertNotEmpty($this->xpath("$xpath_base/input[contains(@data-drupal-selector, 'edit-dropzonejs-uploaded-files')]")); // Upload files path. - $this->assertTrue($this->xpath("$xpath_base/input[contains(@data-upload-path, '/dropzonejs/upload?token=')]")); + $this->assertNotEmpty($this->xpath("$xpath_base/input[contains(@data-upload-path, '/dropzonejs/upload?token=')]")); // Js is attached. - $this->assertTrue($this->xpath("/html/body/script[contains(@src, 'libraries/dropzone/dist/min/dropzone.min.js')]")); - $this->assertTrue($this->xpath("/html/body/script[contains(@src, 'dropzonejs/js/dropzone.integration.js')]")); + $this->assertNotEmpty($this->xpath("/html/body/script[contains(@src, 'libraries/dropzone/dist/min/dropzone.min.js')]")); + $this->assertNotEmpty($this->xpath("/html/body/script[contains(@src, 'dropzonejs/js/dropzone.integration.js')]")); } } diff --git a/web/modules/dropzonejs/tests/src/Kernel/DropzoneJsUploadControllerTest.php b/web/modules/dropzonejs/tests/src/Kernel/DropzoneJsUploadControllerTest.php index c053009a78e7eba5580ca69dba3f6b5813a0adc1..f1bc6bc5a4b73119d5718a1545e874b56293ef03 100644 --- a/web/modules/dropzonejs/tests/src/Kernel/DropzoneJsUploadControllerTest.php +++ b/web/modules/dropzonejs/tests/src/Kernel/DropzoneJsUploadControllerTest.php @@ -57,17 +57,12 @@ class DropzoneJsUploadControllerTest extends KernelTestBase { */ protected function setUp() { parent::setUp(); - $this->installSchema('system', 'router'); $this->installConfig('dropzonejs'); $this->installEntitySchema('user'); $this->filesDir = $this->siteDirectory . '/files'; - $config = $this->container->get('config.factory'); - $config->getEditable('system.file') - ->set('path.temporary', $this->filesDir) - ->save(); + $this->setSetting('file_temp_path', $this->filesDir); - $this->tmpFile = tempnam($this->filesDir, $this->testfilePrefix); $this->tmpFile = tempnam('', $this->testfilePrefix); file_put_contents($this->tmpFile, $this->testfileData); } @@ -94,13 +89,45 @@ public function testDropzoneJsUploadController() { $upload_handler = $this->container->get('dropzonejs.upload_handler'); $controller = new UploadController($upload_handler, $request); $controller_result = $controller->handleUploads(); - $this->assertTrue($controller_result instanceof JsonResponse); + $this->assertInstanceOf(JsonResponse::class, $controller_result); $result = json_decode($controller_result->getContent()); $result_file = $this->filesDir . '/' . $result->result; - $this->assertStringEndsWith('-kapla_aa1.jpg.txt', $result_file); - $this->assertTrue(file_exists($result_file)); + $this->assertStringEndsWith('-kaplya_aa1.jpg.txt', $result_file); + $this->assertFileExists($result_file); $this->assertEquals(file_get_contents($result_file), $this->testfileData); } + /** + * Tests that dropzoneJs ignores filename transliteration. + */ + public function testIgnoreTransliteration() { + $this->container->get('router.builder')->rebuild(); + + $language = ConfigurableLanguage::createFromLangcode('zh-hans'); + $language->save(); + $this->config('system.site')->set('default_langcode', $language->getId())->save(); + $this->config('dropzonejs.settings')->set('filename_transliteration', FALSE)->save(); + + // The filename should be expected as it is. + $chinese_with_emoji_fileanme_without_extension = 'δΈζπ'; + $uploaded_file = new UploadedFile($this->tmpFile, "{$this->testfilePrefix}${chinese_with_emoji_fileanme_without_extension}.jpg"); + $file_bag = new FileBag(); + $file_bag->set('file', $uploaded_file); + + $request = new Request(); + $request->files = $file_bag; + + $upload_handler = $this->container->get('dropzonejs.upload_handler'); + $controller = new UploadController($upload_handler, $request); + $controller_result = $controller->handleUploads(); + $this->assertInstanceOf(JsonResponse::class, $controller_result); + + $result = json_decode($controller_result->getContent()); + $result_file = $this->filesDir . '/' . $result->result; + $this->assertStringEndsWith($chinese_with_emoji_fileanme_without_extension . '.jpg.txt', $result_file); + $this->assertFileExists($result_file); + $this->assertStringEqualsFile($result_file, $this->testfileData); + } + }