Commit f0bed14d authored by webchick's avatar webchick
Browse files

Issue #2233787 by alexpott, xjm | tim.plunkett: Move default configuration...

Issue #2233787 by alexpott, xjm | tim.plunkett: Move default configuration into extension/config/install to clarify its purpose.
parent 37250bb5
......@@ -92,36 +92,36 @@ public function installDefaultConfig($type, $name) {
$source_storage = $this->getSourceStorage();
$config_to_install = $source_storage->listAll($name . '.');
// Work out if this extension provides default configuration for any other
// 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();
}
// If not installing the core base system default configuration, retrieve
// the list of integration configuration of currently enabled extensions.
if ($type !== 'core') {
$default_storage = new FileStorage($config_dir);
$other_module_config = array_filter($default_storage->listAll(), function ($value) use ($name) {
return !preg_match('/^' . $name . '\./', $value);
});
$enabled_extensions = array();
// Read enabled extensions directly from configuration to avoid circular
// dependencies with ModuleHandler and ThemeHandler.
$extension_config = $this->configFactory->get('core.extension');
$enabled_extensions += array_keys((array) $extension_config->get('module'));
$enabled_extensions += array_keys((array) $extension_config->get('theme'));
$other_module_config = array_filter($other_module_config, function ($config_name) use ($enabled_extensions) {
$provider = Unicode::substr($config_name, 0, strpos($config_name, '.'));
return in_array($provider, $enabled_extensions);
});
$config_to_install = array_merge($config_to_install, $other_module_config);
}
$extension_path = drupal_get_path($type, $name);
// If the extension provides configuration schema clear the definitions.
if (is_dir($extension_path . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY)) {
// Refresh the schema cache if installing default configuration and the
// extension has a configuration schema directory.
$this->typedConfig->clearCachedDefinitions();
}
// If not installing the core base system default configuration, work out if
// this extension provides default configuration for any other enabled
// extensions.
if ($type !== 'core' && is_dir($extension_path . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY)) {
$enabled_extensions = $other_module_config = array();
$default_storage = new FileStorage($extension_path . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY);
$other_module_config = array_filter($default_storage->listAll(), function ($value) use ($name) {
return !preg_match('/^' . $name . '\./', $value);
});
// Read enabled extensions directly from configuration to avoid circular
// dependencies with ModuleHandler and ThemeHandler.
$extension_config = $this->configFactory->get('core.extension');
$enabled_extensions += array_keys((array) $extension_config->get('module'));
$enabled_extensions += array_keys((array) $extension_config->get('theme'));
$other_module_config = array_filter($other_module_config, function ($config_name) use ($enabled_extensions) {
$provider = Unicode::substr($config_name, 0, strpos($config_name, '.'));
return in_array($provider, $enabled_extensions);
});
$config_to_install = array_merge($config_to_install, $other_module_config);
}
if (!empty($config_to_install)) {
......
......@@ -19,7 +19,7 @@ interface ConfigInstallerInterface {
* directories for all other extensions to locate any configuration with its
* name prefix. For example, the Node module provides the frontpage view as a
* default configuration file:
* core/modules/node/config/views.view.frontpage.yml
* core/modules/node/config/install/views.view.frontpage.yml
* When the Views module is installed after the Node module is already
* enabled, the frontpage view will be installed.
*
......
......@@ -159,7 +159,7 @@ public function uninstall($type, $name) {
foreach ($config_names as $config_name) {
$this->configFactory->get($config_name)->delete();
}
$schema_dir = drupal_get_path($type, $name) . '/config/schema';
$schema_dir = drupal_get_path($type, $name) . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY;
if (is_dir($schema_dir)) {
// Refresh the schema cache if uninstalling an extension that provides
// configuration schema.
......
......@@ -32,7 +32,7 @@ class ExtensionInstallStorage extends InstallStorage {
* The directory to scan in each extension to scan for files. Defaults to
* 'config'.
*/
public function __construct(StorageInterface $config_storage, $directory = 'config') {
public function __construct(StorageInterface $config_storage, $directory = self::CONFIG_INSTALL_DIRECTORY) {
$this->configStorage = $config_storage;
$this->directory = $directory;
}
......
......@@ -22,6 +22,16 @@
*/
class InstallStorage extends FileStorage {
/**
* Extension sub-directory containing default configuration for installation.
*/
const CONFIG_INSTALL_DIRECTORY = 'config/install';
/**
* Extension sub-directory containing configuration schema.
*/
const CONFIG_SCHEMA_DIRECTORY = 'config/schema';
/**
* Folder map indexed by configuration name.
*
......@@ -43,7 +53,7 @@ class InstallStorage extends FileStorage {
* The directory to scan in each extension to scan for files. Defaults to
* 'config'.
*/
public function __construct($directory = 'config') {
public function __construct($directory = self::CONFIG_INSTALL_DIRECTORY) {
$this->directory = $directory;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment