Commit 48ae9707 authored by catch's avatar catch

Issue #2184387 by alexpott, sun: Remove SchemaStorage.

parent d8a9912c
......@@ -93,8 +93,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:
......
......@@ -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 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 $directory
* The directory to scan in each extension to scan for files. Defaults to
* 'config'.
*/
public function __construct(StorageInterface $config_storage) {
public function __construct(StorageInterface $config_storage, $directory = 'config') {
$this->configStorage = $config_storage;
}
/**
* Resets the static cache.
*/
public function reset() {
$this->folders = NULL;
$this->directory = $directory;
}
/**
......
......@@ -30,9 +30,21 @@ class InstallStorage extends FileStorage {
protected $folders;
/**
* Overrides Drupal\Core\Config\FileStorage::__construct().
* The directory to scan in each extension to scan for files.
*
* @var string
*/
public function __construct() {
protected $directory;
/**
* Constructs an InstallStorage object.
*
* @param string $directory
* The directory to scan in each extension to scan for files. Defaults to
* 'config'.
*/
public function __construct($directory = 'config') {
$this->directory = $directory;
}
/**
......@@ -64,13 +76,20 @@ public function getFilePath($name) {
)));
}
/**
* {@inheritdoc}
*/
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.');
}
/**
......@@ -79,7 +98,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.');
}
/**
......@@ -88,7 +107,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.');
}
/**
......@@ -169,7 +188,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->directory;
}
/**
......@@ -178,7 +197,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;
}
}
<?php
/**
* @file
* Contains \Drupal\Core\Config\Schema\SchemaStorage.
*/
namespace Drupal\Core\Config\Schema;
use Drupal\Core\Config\ExtensionInstallStorage;
use Drupal\Core\Config\StorageException;
/**
* Defines the file storage controller for metadata files.
*/
class SchemaStorage extends ExtensionInstallStorage {
/**
* Implements \Drupal\Core\Config\StorageInterface::exists().
*/
public function exists($name) {
return array_key_exists($name, $this->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.');
}
}
......@@ -8,7 +8,6 @@
namespace Drupal\config\Tests;
use Drupal\config_test\TestInstallStorage;
use Drupal\config_test\TestSchemaStorage;
use Drupal\Core\Config\Schema\Property;
use Drupal\Core\Config\TypedConfigManager;
use Drupal\Core\TypedData\Type\BooleanInterface;
......@@ -70,7 +69,7 @@ public function testDefaultConfig() {
// every module, profile and theme.
$typed_config = new TypedConfigManager(
\Drupal::service('config.storage'),
new TestSchemaStorage(),
new TestInstallStorage('config/schema'),
\Drupal::service('cache.config')
);
......
<?php
/**
* @file
* Contains \Drupal\config_test\TestSchemaStorage.
*/
namespace Drupal\config_test;
use Drupal\Core\Config\Schema\SchemaStorage;
use Drupal\Core\Extension\ExtensionDiscovery;
/**
* Tests configuration schemas of profiles, modules and themes.
*
* A test configuration schema storage to read configuration schema from all
* profiles, modules and themes regardless of installation status or installed
* profile.
*/
class TestSchemaStorage extends SchemaStorage {
/**
* Overrides Drupal\Core\Config\ExtensionInstallStorage::__construct().
*/
public function __construct() {
}
/**
* {@inheritdoc}
*/
protected function getAllFolders() {
if (!isset($this->folders)) {
$this->folders = $this->getComponentNames('core', array('core'));
// @todo Refactor getComponentNames() to use the extension list directly.
$listing = new ExtensionDiscovery();
$listing->setProfileDirectories(array());
$this->folders += $this->getComponentNames('profile', array_keys($listing->scan('profile')));
$this->folders += $this->getComponentNames('module', array_keys($listing->scan('module')));
$this->folders += $this->getComponentNames('theme', array_keys($listing->scan('theme')));
}
return $this->folders;
}
}
......@@ -40,18 +40,13 @@ public static function getInfo() {
*/
public function testHasTranslation() {
$this->installConfig(array('locale_test'));
$locale_config_manager = new LocaleConfigManager(
$this->container->get('config.storage'),
$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->container->get('language_manager')
);
$locale_config_manager = \Drupal::service('locale.config.typed');
$language = new Language(array('id' => 'de'));
$this->assertFalse($locale_config_manager->hasTranslation('locale_test.no_translation', $language), 'There is no translation for locale_test.no_translation configuration.');
$this->assertTrue($locale_config_manager->hasTranslation('locale_test.translation', $language), 'There is a translation for locale_test.translation configuration.');
$result = $locale_config_manager->hasTranslation('locale_test.no_translation', $language);
$this->assertFalse($result, 'There is no translation for locale_test.no_translation configuration.');
$result = $locale_config_manager->hasTranslation('locale_test.translation', $language);
$this->assertTrue($result, 'There is a translation for locale_test.translation configuration.');
}
}
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