From 0791f24a760aeb5e9da27bee45839d0defd0a4f0 Mon Sep 17 00:00:00 2001
From: bjorn <bjorn@swis.nl>
Date: Fri, 11 Apr 2025 09:16:41 +0200
Subject: [PATCH 1/3] feat: make sure ConfigExistsConstraint prefix replaces
 dynamic type expressions.

---
 .../Validation/Constraint/ConfigExistsConstraintValidator.php  | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/core/lib/Drupal/Core/Config/Plugin/Validation/Constraint/ConfigExistsConstraintValidator.php b/core/lib/Drupal/Core/Config/Plugin/Validation/Constraint/ConfigExistsConstraintValidator.php
index fbc7542a7de9..9f6d1188dc88 100644
--- a/core/lib/Drupal/Core/Config/Plugin/Validation/Constraint/ConfigExistsConstraintValidator.php
+++ b/core/lib/Drupal/Core/Config/Plugin/Validation/Constraint/ConfigExistsConstraintValidator.php
@@ -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;
@@ -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]);
     }
-- 
GitLab


From 15bfd7360c7b146487ead3a9dafaac6253f40bbc Mon Sep 17 00:00:00 2001
From: bjorn <bjorn@swis.nl>
Date: Fri, 11 Apr 2025 10:30:03 +0200
Subject: [PATCH 2/3] feat: add test to make sure replacements are working

---
 .../Core/Config/ConfigExistsConstraintValidatorTest.php    | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigExistsConstraintValidatorTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigExistsConstraintValidatorTest.php
index bcdc76cc71d7..dbd75f2432d3 100644
--- a/core/tests/Drupal/KernelTests/Core/Config/ConfigExistsConstraintValidatorTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigExistsConstraintValidatorTest.php
@@ -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
@@ -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);
-- 
GitLab


From faa34f5b4ca6615352699a5f7c1f9c70b421d884 Mon Sep 17 00:00:00 2001
From: bjorn <bjorn@swis.nl>
Date: Fri, 11 Apr 2025 10:32:57 +0200
Subject: [PATCH 3/3] build: phpcs issue

---
 .../Core/Config/ConfigExistsConstraintValidatorTest.php         | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigExistsConstraintValidatorTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigExistsConstraintValidatorTest.php
index dbd75f2432d3..3d3ee862cef6 100644
--- a/core/tests/Drupal/KernelTests/Core/Config/ConfigExistsConstraintValidatorTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigExistsConstraintValidatorTest.php
@@ -41,7 +41,7 @@ public function testValidation(array $constraint_options, string $value, string
 
     // 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']);
+    $parent_data = $typed_data->create($parent_data_definition, ['reference' => 'menu']);
     $data = $typed_data->create($definition, $value, 'data_name', $parent_data);
 
     $violations = $data->validate();
-- 
GitLab