Verified Commit 156533fe authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3404039 by Wim Leers: PluginExistsConstraintValidator should return early if given NULL

parent b20ec518
Loading
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -20,6 +20,10 @@ class PluginExistsConstraintValidator extends ConstraintValidator {
  public function validate(mixed $plugin_id, Constraint $constraint) {
    assert($constraint instanceof PluginExistsConstraint);

    if ($plugin_id === NULL) {
      return;
    }

    $definition = $constraint->pluginManager->getDefinition($plugin_id, FALSE);
    // Some plugin managers provide fallbacks.
    if ($constraint->pluginManager instanceof FallbackPluginManagerInterface) {
+5 −0
Original line number Diff line number Diff line
@@ -61,6 +61,11 @@ public function testValidation(): void {
    $violations = $data->validate();
    $this->assertCount(1, $violations);
    $this->assertSame("The 'action_test_save_entity' plugin must implement or extend " . MenuInterface::class . '.', (string) $violations->get(0)->getMessage());

    // No validation is attempted on a NULL value.
    $data->setValue(NULL);
    $violations = $data->validate();
    $this->assertCount(0, $violations);
  }

}