diff --git a/core/lib/Drupal/Core/Config/Config.php b/core/lib/Drupal/Core/Config/Config.php index e000200..2b54da8 100644 --- a/core/lib/Drupal/Core/Config/Config.php +++ b/core/lib/Drupal/Core/Config/Config.php @@ -57,6 +57,13 @@ class Config extends DependencySerialization { protected $name; /** + * The schema-applicable name of the configuration object. + * + * @var string + */ + protected $schemaName; + + /** * Whether the configuration object is new or has been saved to the storage. * * @var bool @@ -138,7 +145,7 @@ class Config extends DependencySerialization { * The language object used to override configuration data. */ public function __construct($name, StorageInterface $storage, EventDispatcherInterface $event_dispatcher, TypedConfigManager $typed_config, Language $language = NULL) { - $this->name = $name; + $this->setName($name); $this->storage = $storage; $this->eventDispatcher = $event_dispatcher; $this->typedConfigManager = $typed_config; @@ -185,6 +192,7 @@ public function getName() { */ public function setName($name) { $this->name = $name; + $this->schemaName = self::getSchemaName($name); return $this; } @@ -448,7 +456,7 @@ public function save() { // If there is a schema for this configuration object, cast all values to // conform to the schema. - if ($this->typedConfigManager->hasConfigSchema($this->name)) { + if ($this->typedConfigManager->hasConfigSchema($this->schemaName)) { // Ensure that the schema wrapper has the latest data. $this->schemaWrapper = NULL; foreach ($this->data as $key => $value) { @@ -516,7 +524,7 @@ public function merge(array $data_to_merge) { */ protected function getSchemaWrapper() { if (!isset($this->schemaWrapper)) { - $definition = $this->typedConfigManager->getDefinition($this->name); + $definition = $this->typedConfigManager->getDefinition($this->schemaName); $this->schemaWrapper = $this->typedConfigManager->create($definition, $this->data); } return $this->schemaWrapper; @@ -650,5 +658,25 @@ public function getOriginal($key = '', $apply_overrides = TRUE) { } } } + + /** + * Returns schema name for given config name. + * + * @param string $config_name + * String configuration name. + * + * @return string + * String name replaced with prefix patterns. + */ + public static function getSchemaName($config_name) { + $schema_name = $config_name; + // @todo figure out how to allow expandibility. + $optional_prefixes = array(preg_quote(ConfigFactoryInterface::LANGUAGE_CONFIG_PREFIX) . '\.[^\.]+\.'); + foreach ($optional_prefixes as $prefix) { + $schema_name = preg_replace('/^'. $prefix . '(.+)/', '\1', $config_name); + } + return $schema_name; + } + } diff --git a/core/modules/config/lib/Drupal/config/Tests/DefaultConfigTest.php b/core/modules/config/lib/Drupal/config/Tests/DefaultConfigTest.php index b7424f3..bd72223 100644 --- a/core/modules/config/lib/Drupal/config/Tests/DefaultConfigTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/DefaultConfigTest.php @@ -9,6 +9,7 @@ use Drupal\config_test\TestInstallStorage; use Drupal\config_test\TestSchemaStorage; +use Drupal\Core\Config\Config; use Drupal\Core\Config\Schema\Property; use Drupal\Core\Config\TypedConfigManager; use Drupal\Core\TypedData\Type\BooleanInterface; @@ -79,9 +80,10 @@ public function testDefaultConfig() { $default_config_storage = new TestInstallStorage(); foreach ($default_config_storage->listAll() as $config_name) { - // @todo: remove once migration (https://drupal.org/node/2183957) and - // translation (https://drupal.org/node/2168609) schemas are in. - if (strpos($config_name, 'migrate.migration') === 0 || strpos($config_name, 'language.config') === 0) { + $schema_name = Config::getSchemaName($config_name); + + // @todo: remove once migration https://drupal.org/node/2183957 is in. + if (strpos($schema_name, 'migrate.migration') === 0) { continue; } @@ -91,17 +93,17 @@ public function testDefaultConfig() { // type fallback. // 3. config_test.schema_in_install is testing that schema are used during // configuration installation. - if ($config_name == 'config_test.noschema' || $config_name == 'config_test.someschema' || $config_name == 'config_test.schema_in_install') { + if ($schema_name == 'config_test.noschema' || $schema_name == 'config_test.someschema' || $schema_name == 'config_test.schema_in_install') { continue; } $this->configName = $config_name; $data = $default_config_storage->read($config_name); - if (!$typed_config->hasConfigSchema($config_name)) { + if (!$typed_config->hasConfigSchema($schema_name)) { $this->fail(String::format('No schema for !config_name', array('!config_name' => $config_name))); continue; } - $definition = $typed_config->getDefinition($config_name); + $definition = $typed_config->getDefinition($schema_name); $this->schema = $typed_config->create($definition, $data); $this->configPass = TRUE; foreach ($data as $key => $value) { diff --git a/core/modules/tour/tests/tour_test/config/language.config.it.tour.tour.tour-test.yml b/core/modules/tour/tests/tour_test/config/language.config.it.tour.tour.tour-test.yml index e36e435..541674f 100644 --- a/core/modules/tour/tests/tour_test/config/language.config.it.tour.tour.tour-test.yml +++ b/core/modules/tour/tests/tour_test/config/language.config.it.tour.tour.tour-test.yml @@ -3,3 +3,4 @@ tips: tour-test-1: label: La pioggia cade in spagna body: Per lo piĆ¹ in pianura. + plugin: text