diff --git a/core/lib/Drupal/Core/Config/Schema/core.data_types.schema.yml b/core/config/schema/core.data_types.schema.yml similarity index 100% rename from core/lib/Drupal/Core/Config/Schema/core.data_types.schema.yml rename to core/config/schema/core.data_types.schema.yml diff --git a/core/core.services.yml b/core/core.services.yml index 402d6ee..2815912 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -92,8 +92,8 @@ services: class: Drupal\Core\Config\DatabaseStorage arguments: ['@database', config_snapshot] config.storage.schema: - class: Drupal\Core\Config\Schema\SchemaStorage - arguments: ['@config.storage'] + class: Drupal\Core\Config\ExtensionInstallStorage + arguments: ['@config.storage', 'config/schema'] config.storage.installer: class: Drupal\Core\Config\InstallStorage config.typed: diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 9d86cb9..1ac5418 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -374,8 +374,9 @@ function install_begin_request(&$install_state) { $container->register('config.storage', 'Drupal\Core\Config\InstallStorage'); - $container->register('config.storage.schema', 'Drupal\Core\Config\Schema\SchemaStorage') - ->addArgument(new Reference('config.storage')); + $container->register('config.storage.schema', 'Drupal\Core\Config\ExtensionInstallStorage') + ->addArgument(new Reference('config.storage')) + ->addArgument('config/schema'); $container->register('config.typed', 'Drupal\Core\Config\TypedConfigManager') ->addArgument(new Reference('config.storage')) diff --git a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php index 5bedbbe..4e99658 100644 --- a/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php +++ b/core/lib/Drupal/Core/Config/ExtensionInstallStorage.php @@ -7,11 +7,11 @@ namespace Drupal\Core\Config; -use Drupal\Core\Config\InstallStorage; -use Drupal\Core\Config\StorageException; - /** - * Defines the file storage controller for metadata files. + * Storage controller to access configuration and schema in enabled extensions. + * + * @see \Drupal\Core\Config\ConfigInstaller + * @see \Drupal\Core\Config\TypedConfigManager */ class ExtensionInstallStorage extends InstallStorage { @@ -28,16 +28,13 @@ class ExtensionInstallStorage extends InstallStorage { * @param \Drupal\Core\Config\StorageInterface $config_storage * The active configuration store where the list of enabled modules and * themes is stored. + * @param string $folder_to_scan + * The folder to scan in each extension to scan for files. Defaults to + * 'config'. */ - public function __construct(StorageInterface $config_storage) { + public function __construct(StorageInterface $config_storage, $folder_to_scan = 'config') { $this->configStorage = $config_storage; - } - - /** - * Resets the static cache. - */ - public function reset() { - $this->folders = NULL; + $this->folderToScan = $folder_to_scan; } /** @@ -54,7 +51,7 @@ public function reset() { */ protected function getAllFolders() { if (!isset($this->folders)) { - $this->folders = array(); + $this->folders = $this->getCoreComponents(); $modules = $this->configStorage->read('system.module'); if (isset($modules['enabled'])) { $this->folders += $this->getComponentNames('module', array_keys($modules['enabled'])); diff --git a/core/lib/Drupal/Core/Config/InstallStorage.php b/core/lib/Drupal/Core/Config/InstallStorage.php index 16bcc1c..59c8a3f 100644 --- a/core/lib/Drupal/Core/Config/InstallStorage.php +++ b/core/lib/Drupal/Core/Config/InstallStorage.php @@ -22,9 +22,21 @@ class InstallStorage extends FileStorage { protected $folders; /** + * The folder to scan in each extension to scan for files. + * + * @var string + */ + protected $folderToScan; + + /** * Overrides Drupal\Core\Config\FileStorage::__construct(). + * + * @param string $folder_to_scan + * The folder to scan in each extension to scan for files. Defaults to + * 'config'. */ - public function __construct() { + public function __construct($folder_to_scan = 'config') { + $this->folderToScan = $folder_to_scan; } /** @@ -57,12 +69,19 @@ public function getFilePath($name) { } /** + * Implements \Drupal\Core\Config\StorageInterface::exists(). + */ + public function exists($name) { + return array_key_exists($name, $this->getAllFolders()); + } + + /** * Overrides Drupal\Core\Config\FileStorage::write(). * * @throws \Drupal\Core\Config\StorageException */ public function write($name, array $data) { - throw new StorageException('Write operation is not allowed during install.'); + throw new StorageException('Write operation is not allowed.'); } /** @@ -71,7 +90,7 @@ public function write($name, array $data) { * @throws \Drupal\Core\Config\StorageException */ public function delete($name) { - throw new StorageException('Delete operation is not allowed during install.'); + throw new StorageException('Delete operation is not allowed.'); } /** @@ -80,7 +99,7 @@ public function delete($name) { * @throws \Drupal\Core\Config\StorageException */ public function rename($name, $new_name) { - throw new StorageException('Rename operation is not allowed during install.'); + throw new StorageException('Rename operation is not allowed.'); } /** @@ -110,7 +129,8 @@ public function listAll($prefix = '') { */ protected function getAllFolders() { if (!isset($this->folders)) { - $this->folders = $this->getComponentNames('profile', array(drupal_get_profile())); + $this->folders = $this->getCoreComponents(); + $this->folders += $this->getComponentNames('profile', array(drupal_get_profile())); $this->folders += $this->getComponentNames('module', array_keys(drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.module$/', 'modules', 'name', 0))); $this->folders += $this->getComponentNames('theme', array_keys(drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.info.yml$/', 'themes'))); } @@ -118,6 +138,24 @@ protected function getAllFolders() { } /** + * Gets all configuration supplied by core. + * + * @return array + * Array containing items indexed by name with a value of the core directory + * that supplies it. + */ + protected function getCoreComponents() { + $extension = '.' . $this->getFileExtension(); + $folders = array(); + $directory = DRUPAL_ROOT . '/core/' . $this->folderToScan; + $files = new \GlobIterator($directory . '/*' . $extension); + foreach ($files as $file) { + $folders[$file->getBasename($extension)] = $directory; + } + return $folders; + } + + /** * Get all configuration names and folders for a list of modules or themes. * * @param string $type @@ -155,7 +193,7 @@ public function getComponentNames($type, array $list) { * The configuration folder name for this component. */ protected function getComponentFolder($type, $name) { - return drupal_get_path($type, $name) . '/config'; + return drupal_get_path($type, $name) . '/' . $this->folderToScan; } /** @@ -164,7 +202,14 @@ protected function getComponentFolder($type, $name) { * @throws \Drupal\Core\Config\StorageException */ public function deleteAll($prefix = '') { - throw new StorageException('Delete operation is not allowed during install.'); + throw new StorageException('Delete operation is not allowed.'); + } + + /** + * Resets the static cache. + */ + public function reset() { + $this->folders = NULL; } } diff --git a/core/lib/Drupal/Core/Config/Schema/SchemaStorage.php b/core/lib/Drupal/Core/Config/Schema/SchemaStorage.php deleted file mode 100644 index 1b84dec..0000000 --- a/core/lib/Drupal/Core/Config/Schema/SchemaStorage.php +++ /dev/null @@ -1,87 +0,0 @@ -getAllFolders()); - } - - /** - * Overrides \Drupal\Core\Config\InstallStorage::getComponentFolder(). - */ - protected function getComponentFolder($type, $name) { - return drupal_get_path($type, $name) . '/config/schema'; - } - - /** - * Overrides \Drupal\Core\Config\InstallStorage::write(). - * - * @throws \Drupal\Core\Config\StorageException - */ - public function write($name, array $data) { - throw new StorageException('Write operation is not allowed for config schema storage.'); - } - - /** - * Overrides \Drupal\Core\Config\InstallStorage::delete(). - * - * @throws \Drupal\Core\Config\StorageException - */ - public function delete($name) { - throw new StorageException('Delete operation is not allowed for config schema storage.'); - } - - /** - * Overrides \Drupal\Core\Config\InstallStorage::rename(). - * - * @throws \Drupal\Core\Config\StorageException - */ - 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 (!isset($this->folders)) { - parent::getAllFolders(); - $this->folders += $this->getBaseDataTypeSchema(); - } - return $this->folders; - } - - /** - * Gets the base data types for configuration schema. - * - * @return array - * The file containing the base data types for configuration schema. - */ - protected function getBaseDataTypeSchema() { - return array( - 'core.data_types.schema' => 'core/lib/Drupal/Core/Config/Schema' - ); - } - -} diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index 7716a5b..a1568b9 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -182,7 +182,6 @@ public function getDefinitions() { $this->definitions = $cache->data; } else { - $this->definitions = array(); foreach ($this->schemaStorage->readMultiple($this->schemaStorage->listAll()) as $schema) { foreach ($schema as $type => $definition) { $this->definitions[$type] = $definition; diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigManagerTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigManagerTest.php index 16fc30b..a1a9111 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigManagerTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigManagerTest.php @@ -22,7 +22,7 @@ class LocaleConfigManagerTest extends DrupalUnitTestBase { * * @var array */ - public static $modules = array('locale', 'locale_test'); + public static $modules = array('language', 'locale', 'locale_test'); /** * {@inheritdoc} @@ -39,27 +39,11 @@ public static function getInfo() { * Tests hasTranslation(). */ public function testHasTranslation() { - $locale_config_manager = new LocaleConfigManager( - // In contrast to the actual configuration we use the installer storage - // as the config storage. That way, we do not actually have to install - // the module and can extend DrupalUnitTestBase. - $this->container->get('config.storage.installer'), - $this->container->get('config.storage.schema'), - $this->container->get('config.storage.installer'), - $this->container->get('locale.storage'), - $this->container->get('cache.config'), - $this->container->get('config.factory') - ); - + $this->installConfig(array('locale_test')); + $locale_config_manager = \Drupal::Service('locale.config.typed'); $language = new Language(array('id' => 'de')); - // The installer storage throws an expcetion when requesting a non-existing - // file. - try { - $locale_config_manager->hasTranslation('locale_test.no_translation', $language); - } - catch (StorageException $exception) { - $result = FALSE; - } + + $result = $locale_config_manager->hasTranslation('locale_test.no_translation', $language); $this->assertIdentical(FALSE, $result); $result = $locale_config_manager->hasTranslation('locale_test.translation', $language);