Loading core/lib/Drupal/Core/Config/Plugin/Validation/Constraint/ConfigExistsConstraintValidator.php +3 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\Core\Config\Plugin\Validation\Constraint; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\Schema\TypeResolver; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Validator\Constraint; Loading Loading @@ -50,6 +51,8 @@ public function validate(mixed $name, Constraint $constraint): void { return; } $constraint->prefix = TypeResolver::resolveDynamicTypeName($constraint->prefix, $this->context->getObject()); if (!in_array($constraint->prefix . $name, $this->configFactory->listAll($constraint->prefix), TRUE)) { $this->context->addViolation($constraint->message, ['@name' => $constraint->prefix . $name]); } Loading core/tests/Drupal/KernelTests/Core/Config/ConfigExistsConstraintValidatorTest.php +6 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ class ConfigExistsConstraintValidatorTest extends KernelTestBase { * * @testWith [{}, "system.site", "system.site"] * [{"prefix": "system."}, "site", "system.site"] * [{"prefix": "system.[%parent.reference]."}, "admin", "system.menu.admin"] */ public function testValidation(array $constraint_options, string $value, string $expected_config_name): void { // Create a data definition that specifies the value must be a string with Loading @@ -37,7 +38,11 @@ public function testValidation(array $constraint_options, string $value, string /** @var \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data */ $typed_data = $this->container->get('typed_data_manager'); $data = $typed_data->create($definition, $value); // Create a data definition for the parent data. $parent_data_definition = $typed_data->createDataDefinition('map'); $parent_data = $typed_data->create($parent_data_definition, ['reference' => 'menu']); $data = $typed_data->create($definition, $value, 'data_name', $parent_data); $violations = $data->validate(); $this->assertCount(1, $violations); Loading Loading
core/lib/Drupal/Core/Config/Plugin/Validation/Constraint/ConfigExistsConstraintValidator.php +3 −0 Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ namespace Drupal\Core\Config\Plugin\Validation\Constraint; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\Schema\TypeResolver; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Validator\Constraint; Loading Loading @@ -50,6 +51,8 @@ public function validate(mixed $name, Constraint $constraint): void { return; } $constraint->prefix = TypeResolver::resolveDynamicTypeName($constraint->prefix, $this->context->getObject()); if (!in_array($constraint->prefix . $name, $this->configFactory->listAll($constraint->prefix), TRUE)) { $this->context->addViolation($constraint->message, ['@name' => $constraint->prefix . $name]); } Loading
core/tests/Drupal/KernelTests/Core/Config/ConfigExistsConstraintValidatorTest.php +6 −1 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ class ConfigExistsConstraintValidatorTest extends KernelTestBase { * * @testWith [{}, "system.site", "system.site"] * [{"prefix": "system."}, "site", "system.site"] * [{"prefix": "system.[%parent.reference]."}, "admin", "system.menu.admin"] */ public function testValidation(array $constraint_options, string $value, string $expected_config_name): void { // Create a data definition that specifies the value must be a string with Loading @@ -37,7 +38,11 @@ public function testValidation(array $constraint_options, string $value, string /** @var \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data */ $typed_data = $this->container->get('typed_data_manager'); $data = $typed_data->create($definition, $value); // Create a data definition for the parent data. $parent_data_definition = $typed_data->createDataDefinition('map'); $parent_data = $typed_data->create($parent_data_definition, ['reference' => 'menu']); $data = $typed_data->create($definition, $value, 'data_name', $parent_data); $violations = $data->validate(); $this->assertCount(1, $violations); Loading