Skip to content
Snippets Groups Projects
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
No related branches found
Tags 11-42692
Loading
Pipeline #56326 passed
Pipeline: drupal

#56328

    ...@@ -20,6 +20,10 @@ class PluginExistsConstraintValidator extends ConstraintValidator { ...@@ -20,6 +20,10 @@ class PluginExistsConstraintValidator extends ConstraintValidator {
    public function validate(mixed $plugin_id, Constraint $constraint) { public function validate(mixed $plugin_id, Constraint $constraint) {
    assert($constraint instanceof PluginExistsConstraint); assert($constraint instanceof PluginExistsConstraint);
    if ($plugin_id === NULL) {
    return;
    }
    $definition = $constraint->pluginManager->getDefinition($plugin_id, FALSE); $definition = $constraint->pluginManager->getDefinition($plugin_id, FALSE);
    // Some plugin managers provide fallbacks. // Some plugin managers provide fallbacks.
    if ($constraint->pluginManager instanceof FallbackPluginManagerInterface) { if ($constraint->pluginManager instanceof FallbackPluginManagerInterface) {
    ......
    ...@@ -61,6 +61,11 @@ public function testValidation(): void { ...@@ -61,6 +61,11 @@ public function testValidation(): void {
    $violations = $data->validate(); $violations = $data->validate();
    $this->assertCount(1, $violations); $this->assertCount(1, $violations);
    $this->assertSame("The 'action_test_save_entity' plugin must implement or extend " . MenuInterface::class . '.', (string) $violations->get(0)->getMessage()); $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);
    } }
    } }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment