core/config/schema/core.data_types.schema.yml | 4 +++- 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 | 4 +++- .../KernelTests/Core/Config/ConfigEntityValidationTestBase.php | 8 ++++++-- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/core/config/schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml index a115ae89c3..c875fc2d6b 100644 --- a/core/config/schema/core.data_types.schema.yml +++ b/core/config/schema/core.data_types.schema.yml @@ -99,7 +99,9 @@ machine_name: type: string label: 'Machine name' constraints: - Regex: '/^[a-z0-9_]+$/' + Regex: + pattern: '/^[a-z0-9_]+$/' + message: "The %value machine name is not valid." Length: # @see \Drupal\Core\Config\Entity\ConfigEntityStorage::MAX_ID_LENGTH max: 166 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 7dcfd4db58..cb2eadde35 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: 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(