Issue #2233787 by alexpott, xjm | tim.plunkett: Move default configuration into extension/config/install to clarify its purpose.

8.0.x
webchick 2014-04-16 14:59:05 -07:00
parent 37250bb5bb
commit f0bed14de3
274 changed files with 53 additions and 38 deletions

View File

@ -92,36 +92,36 @@ class ConfigInstaller implements ConfigInstallerInterface {
$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'));
$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();
}
$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);
});
// 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);
});
$config_to_install = array_merge($config_to_install, $other_module_config);
}
// 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)) {

View File

@ -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.
*

View File

@ -159,7 +159,7 @@ class ConfigManager implements ConfigManagerInterface {
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.

View File

@ -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;
}

View File

@ -22,6 +22,16 @@ use Drupal\Core\Extension\ExtensionDiscovery;
*/
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;
}

View File

@ -9,6 +9,7 @@ namespace Drupal\config\Tests;
use Drupal\Component\Utility\String;
use Drupal\Core\Config\ConfigNameException;
use Drupal\Core\Config\InstallStorage;
use Drupal\simpletest\DrupalUnitTestBase;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\DatabaseStorage;
@ -196,7 +197,7 @@ class ConfigCRUDTest extends DrupalUnitTestBase {
$storage = new DatabaseStorage($this->container->get('database'), 'config');
$name = 'config_test.types';
$config = $this->container->get('config.factory')->get($name);
$original_content = file_get_contents(drupal_get_path('module', 'config_test') . "/config/$name.yml");
$original_content = file_get_contents(drupal_get_path('module', 'config_test') . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY . "/$name.yml");
$this->verbose('<pre>' . $original_content . "\n" . var_export($storage->read($name), TRUE));
// Verify variable data types are intact.

View File

@ -7,6 +7,7 @@
namespace Drupal\config\Tests;
use Drupal\Core\Config\InstallStorage;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Config\FileStorage;
@ -122,7 +123,7 @@ class ConfigInstallWebTest extends WebTestBase {
// Verify that the original data matches. We have to read the module config
// file directly, because the install profile default system.cron.yml
// configuration file was used to create the active configuration.
$config_dir = drupal_get_path('module', 'system') . '/config';
$config_dir = drupal_get_path('module', 'system') . '/'. InstallStorage::CONFIG_INSTALL_DIRECTORY;
$this->assertTrue(is_dir($config_dir));
$source_storage = new FileStorage($config_dir);
$data = $source_storage->read($config_name);

View File

@ -8,6 +8,7 @@
namespace Drupal\config\Tests;
use Drupal\config_test\TestInstallStorage;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\Schema\Property;
use Drupal\Core\Config\TypedConfigManager;
use Drupal\Core\TypedData\Type\BooleanInterface;
@ -69,7 +70,7 @@ class DefaultConfigTest extends DrupalUnitTestBase {
// every module, profile and theme.
$typed_config = new TypedConfigManager(
\Drupal::service('config.storage'),
new TestInstallStorage('config/schema'),
new TestInstallStorage(InstallStorage::CONFIG_SCHEMA_DIRECTORY),
\Drupal::service('cache.config')
);

Some files were not shown because too many files have changed in this diff Show More