core/modules/block/config/schema/block.schema.yml | 4 +++- core/modules/shortcut/config/schema/shortcut.schema.yml | 4 +++- core/modules/system/config/schema/system.schema.yml | 8 ++++++-- core/modules/tour/config/schema/tour.schema.yml | 4 +++- .../KernelTests/Core/Config/ConfigEntityValidationTestBase.php | 8 ++++++-- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/core/modules/block/config/schema/block.schema.yml b/core/modules/block/config/schema/block.schema.yml index 64dda31dbb..8989c1d79e 100644 --- a/core/modules/block/config/schema/block.schema.yml +++ b/core/modules/block/config/schema/block.schema.yml @@ -11,7 +11,9 @@ block.block.*: # @see https://www.drupal.org/project/drupal/issues/2685917 # @see https://www.drupal.org/project/drupal/issues/2043527 constraints: - Regex: '/^[a-z0-9_.]+$/' + Regex: + pattern: '/^[a-z0-9_.]+$/' + message: "The %value machine name is not valid." theme: type: string label: 'Theme' diff --git a/core/modules/shortcut/config/schema/shortcut.schema.yml b/core/modules/shortcut/config/schema/shortcut.schema.yml index 6fceb5741e..8f32203c65 100644 --- a/core/modules/shortcut/config/schema/shortcut.schema.yml +++ b/core/modules/shortcut/config/schema/shortcut.schema.yml @@ -11,7 +11,9 @@ shortcut.set.*: # dashes but not underscores. # @see \Drupal\shortcut\ShortcutSetForm::form() constraints: - Regex: '/^[a-z0-9-]+$/' + Regex: + pattern: '/^[a-z0-9-]+$/' + message: "The %value machine name is not valid." Length: max: 23 label: diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml index 914f6684f2..9185258749 100644 --- a/core/modules/system/config/schema/system.schema.yml +++ b/core/modules/system/config/schema/system.schema.yml @@ -215,7 +215,9 @@ system.menu.*: # underscores. # @see \Drupal\menu_ui\MenuForm::form() constraints: - Regex: '/^[a-z0-9-]+$/' + Regex: + pattern: '/^[a-z0-9-]+$/' + message: "The %value machine name is not valid." Length: max: 32 label: @@ -236,7 +238,9 @@ system.action.*: type: machine_name constraints: # Action IDs also allow periods. - Regex: '/^[a-z0-9_\.]+$/' + Regex: + pattern: '/^[a-z0-9_\.]+$/' + message: "The %value machine name is not valid." label: 'ID' label: type: label diff --git a/core/modules/tour/config/schema/tour.schema.yml b/core/modules/tour/config/schema/tour.schema.yml index 7117f4b4ef..4cba7ce565 100644 --- a/core/modules/tour/config/schema/tour.schema.yml +++ b/core/modules/tour/config/schema/tour.schema.yml @@ -8,7 +8,9 @@ tour.tour.*: type: machine_name # Tour IDs also allow dashes. constraints: - Regex: '/^[a-z0-9_-]+$/' + Regex: + pattern: '/^[a-z0-9_-]+$/' + message: "The %value machine name is not valid." label: 'ID' label: type: label diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php index 2aa8cedb87..436f63adcc 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigEntityValidationTestBase.php @@ -102,14 +102,18 @@ public function testInvalidMachineNameCharacters(string $machine_name, bool $is_ $constraints = $this->getMachineNameConstraints(); $this->assertNotEmpty($constraints['Regex']); - $this->assertIsString($constraints['Regex']); + $this->assertIsArray($constraints['Regex']); + $this->assertArrayHasKey('pattern', $constraints['Regex']); + $this->assertIsString($constraints['Regex']['pattern']); + $this->assertArrayHasKey('message', $constraints['Regex']); + $this->assertIsString($constraints['Regex']['message']); $id_key = $this->entity->getEntityType()->getKey('id'); if ($is_expected_to_be_valid) { $expected_errors = []; } else { - $expected_errors = [$id_key => 'This value is not valid.']; + $expected_errors = [$id_key => sprintf('The "%s" machine name is not valid.', $machine_name)]; } $this->entity->set(