Loading core/config/schema/core.data_types.schema.yml +4 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -233,6 +235,7 @@ theme_settings: label: 'Logo path' url: type: uri nullable: true label: 'URL' use_default: type: boolean Loading core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php +29 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ use Drupal\Core\TypedData\Type\StringInterface; use Drupal\Core\TypedData\Type\FloatInterface; use Drupal\Core\TypedData\Type\IntegerInterface; use Symfony\Component\Validator\ConstraintViolation; /** * Provides a trait for checking configuration schema. Loading Loading @@ -57,6 +58,34 @@ public function checkConfigSchema(TypedConfigManagerInterface $typed_config, $co $errors[] = $this->checkValue($key, $value); } $errors = array_merge(...$errors); // Also perform explicit validation. Note this does NOT require every node // in the config schema tree to have validation constraints defined. $violations = $this->schema->validate(); $ignored_validation_constraint_messages = [ // @see \Drupal\Core\Config\Plugin\Validation\Constraint\ConfigExistsConstraint::$message // @todo Remove this in https://www.drupal.org/project/drupal/issues/3362453 "The '.*' config does not exist.", // @see \Drupal\Core\Extension\Plugin\Validation\Constraint\ExtensionExistsConstraint::$moduleMessage // @see \Drupal\Core\Extension\Plugin\Validation\Constraint\ExtensionExistsConstraint::$themeMessage // @todo Remove this in https://www.drupal.org/project/drupal/issues/3362456 "Module '.*' is not installed.", "Theme '.*' is not installed.", // @see \Drupal\Core\Plugin\Plugin\Validation\Constraint\PluginExistsConstraint::$unknownPluginMessage // @todo Remove this in https://www.drupal.org/project/drupal/issues/3362457 "The '.*' plugin does not exist.", // @see "machine_name" in core.data_types.schema.yml // @todo Remove this in https://www.drupal.org/project/drupal/issues/3372972 "The <em class=\"placeholder\">.*<\/em> machine name is not valid.", ]; $filtered_violations = array_filter( iterator_to_array($violations), fn (ConstraintViolation $v) => preg_match(sprintf("/^(%s)$/", implode('|', $ignored_validation_constraint_messages)), (string) $v->getMessage()) !== 1 ); $validation_errors = array_map( fn (ConstraintViolation $v) => sprintf("[%s] %s", $v->getPropertyPath(), (string) $v->getMessage()), $filtered_violations ); $errors = array_merge($errors, $validation_errors); if (empty($errors)) { return TRUE; } Loading core/modules/block/config/schema/block.schema.yml +3 −1 Original line number Diff line number Diff line Loading @@ -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' Loading core/modules/block/tests/src/Functional/BlockTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -580,6 +580,7 @@ public function testBlockUserRoleDelete() { $block = Block::create([ 'id' => $this->randomMachineName(), 'plugin' => 'system_powered_by_block', 'theme' => 'stark', ]); $block->setVisibilityConfig('user_role', [ Loading core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -69,7 +69,7 @@ public function testDeletingBlockContentShouldClearPluginCache() { $block_content->save(); $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid(); $block = $this->placeBlock($plugin_id, ['region' => 'content']); $block = $this->placeBlock($plugin_id, ['region' => 'content', 'theme' => 'stark']); // Delete it via storage. $storage = $this->container->get('entity_type.manager')->getStorage('block_content'); Loading Loading
core/config/schema/core.data_types.schema.yml +4 −1 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -233,6 +235,7 @@ theme_settings: label: 'Logo path' url: type: uri nullable: true label: 'URL' use_default: type: boolean Loading
core/lib/Drupal/Core/Config/Schema/SchemaCheckTrait.php +29 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ use Drupal\Core\TypedData\Type\StringInterface; use Drupal\Core\TypedData\Type\FloatInterface; use Drupal\Core\TypedData\Type\IntegerInterface; use Symfony\Component\Validator\ConstraintViolation; /** * Provides a trait for checking configuration schema. Loading Loading @@ -57,6 +58,34 @@ public function checkConfigSchema(TypedConfigManagerInterface $typed_config, $co $errors[] = $this->checkValue($key, $value); } $errors = array_merge(...$errors); // Also perform explicit validation. Note this does NOT require every node // in the config schema tree to have validation constraints defined. $violations = $this->schema->validate(); $ignored_validation_constraint_messages = [ // @see \Drupal\Core\Config\Plugin\Validation\Constraint\ConfigExistsConstraint::$message // @todo Remove this in https://www.drupal.org/project/drupal/issues/3362453 "The '.*' config does not exist.", // @see \Drupal\Core\Extension\Plugin\Validation\Constraint\ExtensionExistsConstraint::$moduleMessage // @see \Drupal\Core\Extension\Plugin\Validation\Constraint\ExtensionExistsConstraint::$themeMessage // @todo Remove this in https://www.drupal.org/project/drupal/issues/3362456 "Module '.*' is not installed.", "Theme '.*' is not installed.", // @see \Drupal\Core\Plugin\Plugin\Validation\Constraint\PluginExistsConstraint::$unknownPluginMessage // @todo Remove this in https://www.drupal.org/project/drupal/issues/3362457 "The '.*' plugin does not exist.", // @see "machine_name" in core.data_types.schema.yml // @todo Remove this in https://www.drupal.org/project/drupal/issues/3372972 "The <em class=\"placeholder\">.*<\/em> machine name is not valid.", ]; $filtered_violations = array_filter( iterator_to_array($violations), fn (ConstraintViolation $v) => preg_match(sprintf("/^(%s)$/", implode('|', $ignored_validation_constraint_messages)), (string) $v->getMessage()) !== 1 ); $validation_errors = array_map( fn (ConstraintViolation $v) => sprintf("[%s] %s", $v->getPropertyPath(), (string) $v->getMessage()), $filtered_violations ); $errors = array_merge($errors, $validation_errors); if (empty($errors)) { return TRUE; } Loading
core/modules/block/config/schema/block.schema.yml +3 −1 Original line number Diff line number Diff line Loading @@ -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' Loading
core/modules/block/tests/src/Functional/BlockTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -580,6 +580,7 @@ public function testBlockUserRoleDelete() { $block = Block::create([ 'id' => $this->randomMachineName(), 'plugin' => 'system_powered_by_block', 'theme' => 'stark', ]); $block->setVisibilityConfig('user_role', [ Loading
core/modules/block_content/tests/src/Kernel/BlockContentDeletionTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -69,7 +69,7 @@ public function testDeletingBlockContentShouldClearPluginCache() { $block_content->save(); $plugin_id = 'block_content' . PluginBase::DERIVATIVE_SEPARATOR . $block_content->uuid(); $block = $this->placeBlock($plugin_id, ['region' => 'content']); $block = $this->placeBlock($plugin_id, ['region' => 'content', 'theme' => 'stark']); // Delete it via storage. $storage = $this->container->get('entity_type.manager')->getStorage('block_content'); Loading