Skip to content
Snippets Groups Projects
Commit d8010df5 authored by Sascha Grossenbacher's avatar Sascha Grossenbacher
Browse files

Issue #3452801 by Berdir: Drupal 11 compatibility

parent 9a49b6d3
Branches
Tags
1 merge request!16Drupal 11 compatibility
Pipeline #250260 passed with warnings
......@@ -51,8 +51,6 @@ include:
variables:
_PHPUNIT_CONCURRENT: '1'
OPT_IN_TEST_PREVIOUS_MINOR: 1
OPT_IN_TEST_NEXT_MINOR: 1
OPT_IN_TEST_MAX_PHP: 1
DROPZONE_VERSION: v5.9.3
.composer-base:
......
......@@ -39,9 +39,6 @@
"role": "contributor"
}
],
"require": {
"drupal/core": "^9.3 || ^10"
},
"require-dev": {
"drupal/entity_browser": "^2.5"
},
......
name: dropzonejs
type: module
description: The Drupal integration for DropzoneJS.
core_version_requirement: ^9.3 || ^10
core_version_requirement: ^9.3 || ^10 || ^11
package: Media
dependencies:
- drupal:file
name: DropzoneJS entity browser widget
type: module
description: 'DropzoneJS Entity browser widget.'
core_version_requirement: ^9.3 || ^10
core_version_requirement: ^9.3 || ^10 || ^11
package: Media
dependencies:
- drupal:file
......
......@@ -352,7 +352,7 @@ class DropzoneJsEbWidget extends WidgetBase {
* Validate extension.
*
* Because while validating we don't have a file object yet, we can't use
* file_validate_extensions directly. That's why we make a copy of that
* FileExtension directly. That's why we make a copy of that
* function here and switch the file argument with filename argument.
*
* @param string $filename
......@@ -546,7 +546,7 @@ class DropzoneJsEbWidget extends WidgetBase {
/**
* {@inheritdoc}
*/
public function __sleep() {
public function __sleep(): array {
return array_diff(parent::__sleep(), ['files']);
}
......
......@@ -202,13 +202,38 @@ class DropzoneJsUploadSave implements DropzoneJsUploadSaveInterface {
public function validateFile(FileInterface $file, $extensions, array $additional_validators = []) {
$validators = $additional_validators;
if (!empty($extensions)) {
$validators['file_validate_extensions'] = [$extensions];
// Call the validation functions specified by this function's caller.
if (\Drupal::getContainer()->has('file.validator')) {
if (!empty($extensions)) {
$validators['FileExtension'] = ['extensions' => $extensions];
}
$validators['FileNameLength'] = [];
// Convert size validator, drop this when removing support for
// file_validate().
if (isset($validators['file_validate_size'][0])) {
$validators['FileSizeLimit'] = ['fileLimit' => $validators['file_validate_size'][0]];
unset($validators['file_validate_size']);
}
$violations = \Drupal::service('file.validator')->validate($file, $validators);
$errors = [];
foreach ($violations as $violation) {
$errors[] = $violation->getMessage();
}
return $errors;
}
$validators['file_validate_name_length'] = [];
else {
// Call the validation functions specified by this function's caller.
return file_validate($file, $validators);
if (!empty($extensions)) {
$validators['file_validate_extensions'] = [$extensions];
}
$validators['file_validate_name_length'] = [];
// @phpstan-ignore-next-line
return file_validate($file, $validators);
}
}
/**
......
......@@ -27,9 +27,9 @@ interface DropzoneJsUploadSaveInterface {
* The owner of the file.
* @param array $validators
* (Optional) Associative array of callback functions used to validate the
* file. See file_validate() for more documentation. Note that we add
* file_validate_extensions and file_validate_name_length in this method
* already.
* file. See \Drupal\file\Validation\FileValidatorInterface for more
* documentation. Note that we add FileExtension and FileNameLength in this
* method already.
*
* @return \Drupal\file\FileInterface|bool
* The file entity of the newly uploaded file or false in case of a failure.
......@@ -45,10 +45,10 @@ interface DropzoneJsUploadSaveInterface {
* @param string $extensions
* A space separated string of valid extensions.
* @param array $additional_validators
* An optional, associative array of callback functions used to validate the
* file. See file_validate() for more documentation. Note that we add
* file_validate_extensions and file_validate_name_length in this method
* already.
* (Optional) Associative array of callback functions used to validate the
* * file. See \Drupal\file\Validation\FileValidatorInterface for more
* * documentation. Note that we add FileExtension and FileNameLength in this
* * method already.
*
* @return array
* An array containing validation error messages.
......
......@@ -59,8 +59,8 @@ class DropzoneJsEbWidgetTest extends DropzoneJsWebDriverTestBase {
$this->getSession()->getPage()->pressButton('Select entities');
// Switch back to the main page.
$this->getSession()->switchToIFrame();
$this->waitForAjaxToFinish();
$this->getSession()->switchToIFrame();
// For some reason we have to wait here for the markup to show up regardless
// of the waitForAjaxToFinish above.
sleep(2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment