Skip to content
Snippets Groups Projects
Commit 97c49565 authored by catch's avatar catch
Browse files

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

parent 3951fa4d
No related branches found
No related tags found
No related merge requests found
......@@ -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]);
}
......
......@@ -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());
}
}
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