Issue #3410126 by kim.pepper, catch, larowlan, DamienMcKenna, alexpott: File validation logic from #3221793 broke backwards compatibility

merge-requests/4109/merge
Lee Rowlands 2024-01-02 06:51:05 +10:00
parent f47d1d159e
commit bd37e393c3
No known key found for this signature in database
GPG Key ID: 2B829A3DF9204DC4
2 changed files with 10 additions and 1 deletions

View File

@ -2,6 +2,7 @@
namespace Drupal\file\Validation;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Validation\ConstraintManager;
use Drupal\Core\Validation\DrupalTranslator;
@ -53,7 +54,12 @@ class FileValidator implements FileValidatorInterface {
else {
// Create the constraint.
// Options are an associative array of constraint properties and values.
$constraints[] = $this->constraintManager->create($validator, $options);
try {
$constraints[] = $this->constraintManager->create($validator, $options);
}
catch (PluginNotFoundException) {
@trigger_error(sprintf('Passing invalid constraint plugin ID "%s" in the list of $validators to Drupal\file\Validation\FileValidator::validate() is deprecated in drupal:10.2.0 and will throw an exception in drupal:11.0.0. See https://www.drupal.org/node/3363700', $validator), E_USER_DEPRECATED);
}
}
}

View File

@ -31,9 +31,11 @@ class FileValidatorTest extends FileValidatorTestBase {
// Use a mix of legacy functions and plugin IDs to test both work.
// Each Constraint has its own tests under
// core/modules/file/tests/src/Kernel/Plugin/Validation/Constraint.
// Also check that arbitrary strings can be used.
$validators = [
'file_validate_name_length' => [],
'FileNameLength' => [],
'foo' => [],
];
file_test_reset();
@ -42,6 +44,7 @@ class FileValidatorTest extends FileValidatorTestBase {
$this->assertCount(0, $violations);
$this->assertCount(1, file_test_get_calls('validate'));
$this->expectDeprecation('Passing invalid constraint plugin ID "foo" in the list of $validators to Drupal\file\Validation\FileValidator::validate() is deprecated in drupal:10.2.0 and will throw an exception in drupal:11.0.0. See https://www.drupal.org/node/3363700');
file_test_reset();
$this->file->set('filename', '');
$violations = $this->validator->validate($this->file, $validators);