Verified Commit bb42fa92 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3410126 by kim.pepper, catch, larowlan, DamienMcKenna, alexpott: File...

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

(cherry picked from commit bd37e393)
parent c2090141
Loading
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -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,8 +54,13 @@ public function validate(FileInterface $file, array $validators): ConstraintViol
      else {
        // Create the constraint.
        // Options are an associative array of constraint properties and values.
        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);
        }
      }
    }

    // Call legacy hook implementations.
+3 −0
Original line number Diff line number Diff line
@@ -31,9 +31,11 @@ public function testValidate(): void {
    // 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 @@ public function testValidate(): void {
    $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);