diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php index dc4f3b9..d7294b8 100644 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ b/core/lib/Drupal/Core/Config/ConfigInstaller.php @@ -82,6 +82,11 @@ public function installDefaultConfig($type, $name) { // enabled extensions. $config_dir = drupal_get_path($type, $name) . '/config'; if (is_dir($config_dir)) { + if (is_dir($config_dir . '/schema')) { + // Refresh the schema cache if installing default configuration and the + // extension has a configuration schema directory. + $this->typedConfig->clearCachedDefinitions(); + } $default_storage = new FileStorage($config_dir); $other_module_config = array_filter($default_storage->listAll(), function ($value) use ($name) { return !preg_match('/^' . $name . '\./', $value); diff --git a/core/lib/Drupal/Core/Config/Schema/SchemaStorage.php b/core/lib/Drupal/Core/Config/Schema/SchemaStorage.php index 171f30a..f3a689c 100644 --- a/core/lib/Drupal/Core/Config/Schema/SchemaStorage.php +++ b/core/lib/Drupal/Core/Config/Schema/SchemaStorage.php @@ -7,13 +7,13 @@ namespace Drupal\Core\Config\Schema; -use Drupal\Core\Config\InstallStorage; +use Drupal\Core\Config\ExtensionInstallStorage; use Drupal\Core\Config\StorageException; /** * Defines the file storage controller for metadata files. */ -class SchemaStorage extends InstallStorage { +class SchemaStorage extends ExtensionInstallStorage { /** * Implements \Drupal\Core\Config\StorageInterface::exists(). @@ -56,4 +56,26 @@ public function rename($name, $new_name) { throw new StorageException('Rename operation is not allowed for config schema storage.'); } + /** + * Returns a map of all config object names and their folders. + * + * The list is based on enabled modules and themes. + * + * @return array + * An array mapping config object names with directories. + */ + protected function getAllFolders() { + if (empty($this->folders)) { + parent::getAllFolders(); + + // Ensure that the system schema are available as the base types used by + // all config schema are defined here. + if (!isset($this->folders['system.schema'])) { + $this->folders += $this->getComponentNames('module', array('system')); + } + + } + return $this->folders; + } + } diff --git a/core/lib/Drupal/Core/Config/TypedConfigManagerInterface.php b/core/lib/Drupal/Core/Config/TypedConfigManagerInterface.php index 58a8850..b990c8b 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManagerInterface.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManagerInterface.php @@ -7,12 +7,15 @@ namespace Drupal\Core\Config; +use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface; +use Drupal\Component\Plugin\PluginManagerInterface; + /** * Defines an interface for typed configuration manager. * * @package Drupal\Core\Config */ -Interface TypedConfigManagerInterface { +Interface TypedConfigManagerInterface extends PluginManagerInterface, CachedDiscoveryInterface { /** * Checks if the configuration schema with the given config name exists. @@ -24,4 +27,5 @@ * TRUE if configuration schema exists, FALSE otherwise. */ public function hasConfigSchema($name); + } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php index 992c1bd..18e6a13 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php @@ -2,7 +2,7 @@ /** * @file - * Definition of Drupal\config\Tests\ConfigInstallTest. + * Contains \Drupal\config\Tests\ConfigInstallTest. */ namespace Drupal\config\Tests; @@ -42,10 +42,17 @@ function testModuleInstallation() { $config = \Drupal::config($default_configuration_entity); $this->assertIdentical($config->isNew(), TRUE); + // Ensure that schema provided by modules that are not installed is not + // available. + $this->assertFalse(\Drupal::service('config.typed')->hasConfigSchema('config_test.schema_in_install'), 'Configuration schema for config_test.schema_in_install does not exist.'); + // Install the test module. $this->enableModules(array('config_test')); $this->installConfig(array('config_test')); + // After module installation the new schema should exist. + $this->assertTrue(\Drupal::service('config.typed')->hasConfigSchema('config_test.schema_in_install'), 'Configuration schema for config_test.schema_in_install exists.'); + // Verify that default module config exists. \Drupal::configFactory()->reset($default_config); \Drupal::configFactory()->reset($default_configuration_entity); @@ -62,5 +69,10 @@ function testModuleInstallation() { $this->assertFalse(isset($GLOBALS['hook_config_test']['update'])); $this->assertFalse(isset($GLOBALS['hook_config_test']['predelete'])); $this->assertFalse(isset($GLOBALS['hook_config_test']['delete'])); + + // Ensure that data type casting is applied during config installation. + $config = \Drupal::config('config_test.schema_in_install'); + $this->assertIdentical($config->get('integer'), 1); + } } diff --git a/core/modules/config/tests/config_test/config/config_test.schema_in_install.yml b/core/modules/config/tests/config_test/config/config_test.schema_in_install.yml new file mode 100644 index 0000000..41badc1 --- /dev/null +++ b/core/modules/config/tests/config_test/config/config_test.schema_in_install.yml @@ -0,0 +1 @@ +integer: '1' \ No newline at end of file diff --git a/core/modules/config/tests/config_test/config/schema/config_test.schema.yml b/core/modules/config/tests/config_test/config/schema/config_test.schema.yml index 597e9f7..48cc244 100644 --- a/core/modules/config/tests/config_test/config/schema/config_test.schema.yml +++ b/core/modules/config/tests/config_test/config/schema/config_test.schema.yml @@ -131,3 +131,11 @@ config_test.schema_data_types: type: sequence sequence: - type: boolean + +config_test.schema_in_install: + label: 'Schema test data with parenting' + type: mapping + mapping: + integer: + type: integer + label: 'Integer'