Commit a7d396f1 authored by catch's avatar catch
Browse files

Issue #3416549 by Wim Leers: ConfigExistsConstraintValidator should ignore NULL values

(cherry picked from commit 97c49565)
parent 64a66d9a
Loading
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -43,6 +43,11 @@ public static function create(ContainerInterface $container) {
   * {@inheritdoc}
   */
  public function validate(mixed $name, Constraint $constraint) {
    // This constraint may be used to validate nullable (optional) values.
    if ($name === NULL) {
      return;
    }

    if (!in_array($name, $this->configFactory->listAll(), TRUE)) {
      $this->context->addViolation($constraint->message, ['@name' => $name]);
    }
+4 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@ public function testValidation(): void {

    $this->installConfig('system');
    $this->assertCount(0, $data->validate());

    // NULL should not trigger a validation error: a value may be nullable.
    $data->setValue(NULL);
    $this->assertCount(0, $data->validate());
  }

}