diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index 51ade6c..bd0ccc4 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -68,6 +68,8 @@ class Config extends StorableConfigBase { * The typed configuration manager service. */ public function __construct($name, StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManagerInterface $typed_config) { + // Validate the configuration object name. + static::validateName($name); $this->name = $name; $this->storage = $storage; $this->eventDispatcher = $event_dispatcher; @@ -204,9 +206,6 @@ public function clear($key) { * {@inheritdoc} */ public function save() { - // Validate the configuration object name before saving. - static::validateName($this->name); - // If there is a schema for this configuration object, cast all values to // conform to the schema. if ($this->typedConfigManager->hasConfigSchema($this->name)) { diff --git a/core/lib/Drupal/Core/Config/ConfigBase.php b/core/lib/Drupal/Core/Config/ConfigBase.php index eee76a2..f89b1e5 100644 --- a/core/lib/Drupal/Core/Config/ConfigBase.php +++ b/core/lib/Drupal/Core/Config/ConfigBase.php @@ -80,6 +80,8 @@ public function getName() { * The configuration object. */ public function setName($name) { + // Validate the configuration object. + static::validateName($name); $this->name = $name; return $this; } @@ -87,6 +89,11 @@ public function setName($name) { /** * Validates the configuration object name. * + * A valid name must: + * - Be namespaced by its owner (i.e. contain at least one '.'). + * - Be shorter than Config::MAX_NAME_LENGTH characters. + * - Not contain any of the following characters: ? : * < > " ' / \ + * * @param string $name * The name of the configuration object. * @@ -95,7 +102,7 @@ public function setName($name) { * @see Config::MAX_NAME_LENGTH */ public static function validateName($name) { - // The name must be namespaced by owner. + // The name must be namespaced by its owner. if (strpos($name, '.') === FALSE) { throw new ConfigNameException(SafeMarkup::format('Missing namespace in Config object name @name.', array( '@name' => $name,