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,23 +92,24 @@ class ConfigInstaller implements ConfigInstallerInterface {
$source_storage = $this->getSourceStorage(); $source_storage = $this->getSourceStorage();
$config_to_install = $source_storage->listAll($name . '.'); $config_to_install = $source_storage->listAll($name . '.');
// Work out if this extension provides default configuration for any other $extension_path = drupal_get_path($type, $name);
// enabled extensions. // If the extension provides configuration schema clear the definitions.
$config_dir = drupal_get_path($type, $name) . '/config'; if (is_dir($extension_path . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY)) {
if (is_dir($config_dir)) {
if (is_dir($config_dir . '/schema')) {
// Refresh the schema cache if installing default configuration and the // Refresh the schema cache if installing default configuration and the
// extension has a configuration schema directory. // extension has a configuration schema directory.
$this->typedConfig->clearCachedDefinitions(); $this->typedConfig->clearCachedDefinitions();
} }
// If not installing the core base system default configuration, retrieve
// the list of integration configuration of currently enabled extensions. // If not installing the core base system default configuration, work out if
if ($type !== 'core') { // this extension provides default configuration for any other enabled
$default_storage = new FileStorage($config_dir); // 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) { $other_module_config = array_filter($default_storage->listAll(), function ($value) use ($name) {
return !preg_match('/^' . $name . '\./', $value); return !preg_match('/^' . $name . '\./', $value);
}); });
$enabled_extensions = array();
// Read enabled extensions directly from configuration to avoid circular // Read enabled extensions directly from configuration to avoid circular
// dependencies with ModuleHandler and ThemeHandler. // dependencies with ModuleHandler and ThemeHandler.
$extension_config = $this->configFactory->get('core.extension'); $extension_config = $this->configFactory->get('core.extension');
@ -122,7 +123,6 @@ class ConfigInstaller implements ConfigInstallerInterface {
$config_to_install = array_merge($config_to_install, $other_module_config); $config_to_install = array_merge($config_to_install, $other_module_config);
} }
}
if (!empty($config_to_install)) { if (!empty($config_to_install)) {
// Order the configuration to install in the order of dependencies. // Order the configuration to install in the order of dependencies.

View File

@ -19,7 +19,7 @@ interface ConfigInstallerInterface {
* directories for all other extensions to locate any configuration with its * directories for all other extensions to locate any configuration with its
* name prefix. For example, the Node module provides the frontpage view as a * name prefix. For example, the Node module provides the frontpage view as a
* default configuration file: * 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 * When the Views module is installed after the Node module is already
* enabled, the frontpage view will be installed. * enabled, the frontpage view will be installed.
* *

View File

@ -159,7 +159,7 @@ class ConfigManager implements ConfigManagerInterface {
foreach ($config_names as $config_name) { foreach ($config_names as $config_name) {
$this->configFactory->get($config_name)->delete(); $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)) { if (is_dir($schema_dir)) {
// Refresh the schema cache if uninstalling an extension that provides // Refresh the schema cache if uninstalling an extension that provides
// configuration schema. // 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 * The directory to scan in each extension to scan for files. Defaults to
* 'config'. * '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->configStorage = $config_storage;
$this->directory = $directory; $this->directory = $directory;
} }

View File

@ -22,6 +22,16 @@ use Drupal\Core\Extension\ExtensionDiscovery;
*/ */
class InstallStorage extends FileStorage { 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. * 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 * The directory to scan in each extension to scan for files. Defaults to
* 'config'. * 'config'.
*/ */
public function __construct($directory = 'config') { public function __construct($directory = self::CONFIG_INSTALL_DIRECTORY) {
$this->directory = $directory; $this->directory = $directory;
} }

View File

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

View File

@ -7,6 +7,7 @@
namespace Drupal\config\Tests; namespace Drupal\config\Tests;
use Drupal\Core\Config\InstallStorage;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\Core\Config\FileStorage; 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 // Verify that the original data matches. We have to read the module config
// file directly, because the install profile default system.cron.yml // file directly, because the install profile default system.cron.yml
// configuration file was used to create the active configuration. // 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)); $this->assertTrue(is_dir($config_dir));
$source_storage = new FileStorage($config_dir); $source_storage = new FileStorage($config_dir);
$data = $source_storage->read($config_name); $data = $source_storage->read($config_name);

View File

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

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