Commit faaddf2f authored by catch's avatar catch
Browse files

Issue #1914366 by vijaycs85, Gábor Hojtsy, alexpott: Move all configuration...

Issue #1914366 by vijaycs85, Gábor Hojtsy, alexpott: Move all configuration schema files into a schema subdirectory.
parent 4ab57bed
......@@ -14,6 +14,13 @@
*/
class InstallStorage extends FileStorage {
/**
* Folder map indexed by configuration name.
*
* @var array
*/
protected $folders;
/**
* Overrides Drupal\Core\Config\FileStorage::__construct().
*/
......@@ -38,17 +45,9 @@ public function __construct() {
* afterwards check for a corresponding module or theme.
*/
public function getFilePath($name) {
// Extract the owner.
$owner = strtok($name, '.');
// Determine the path to the owner.
$path = FALSE;
foreach (array('profile', 'module', 'theme') as $type) {
if ($path = drupal_get_path($type, $owner)) {
$file = $path . '/config/' . $name . '.' . static::getFileExtension();
if (file_exists($file)) {
return $file;
}
}
$folders = $this->getAllFolders();
if (isset($folders[$name])) {
return $folders[$name] . '/' . $name . '.' . $this->getFileExtension();
}
// If any code in the early installer requests a configuration object that
// does not exist anywhere as default config, then that must be mistake.
......@@ -86,12 +85,79 @@ public function rename($name, $new_name) {
/**
* Implements Drupal\Core\Config\StorageInterface::listAll().
*
* @throws Drupal\Core\Config\StorageException
*/
public function listAll($prefix = '') {
throw new StorageException('List operation is not allowed during install.');
}
$names = array_keys($this->getAllFolders());
if (!$prefix) {
return $names;
}
else {
$return = array();
foreach ($names as $index => $name) {
if (strpos($name, $prefix) === 0 ) {
$return[$index] = $names[$index];
}
}
return $return;
}
}
/**
* Returns a map of all config object names and their folders.
*
* @return array
* An array mapping config object names with directories.
*/
protected function getAllFolders() {
if (!isset($this->folders)) {
$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$/', 'themes')));
}
return $this->folders;
}
/**
* Get all configuration names and folders for a list of modules or themes.
*
* @param string $type
* Type of components: 'module' | 'theme' | 'profile'
* @param array $list
* Array of theme or module names.
*
* @return array
* Folders indexed by configuration name.
*/
protected function getComponentNames($type, array $list) {
$extension = '.' . $this->getFileExtension();
$folders = array();
foreach ($list as $name) {
$directory = $this->getComponentFolder($type, $name);
if (file_exists($directory)) {
$files = glob($directory . '/*' . $extension);
foreach ($files as $filename) {
$name = basename($filename, $extension);
$folders[$name] = $directory;
}
}
}
return $folders;
}
/**
* Get folder inside each component that contains the files.
*
* @param string $type
* Component type: 'module' | 'theme' | 'profile'
* @param string $name
* Component name.
*
* @return string
* The configuration folder name for this component.
*/
protected function getComponentFolder($type, $name) {
return drupal_get_path($type, $name) . '/config';
}
/**
* Overrides Drupal\Core\Config\FileStorage::deleteAll().
......
......@@ -38,12 +38,7 @@ class SchemaDiscovery implements DiscoveryInterface {
*/
public function __construct($storage) {
$this->storage = $storage;
// Load definitions for all enabled modules.
foreach (module_list() as $module) {
$this->loadSchema($module);
}
// @todo Load definitions for all enabled themes.
$this->loadAllSchema();
}
/**
......@@ -84,11 +79,12 @@ public function getDefinitions() {
/**
* Load schema for module / theme.
*/
protected function loadSchema($component) {
if ($schema = $this->storage->read($component . '.schema')) {
foreach ($schema as $type => $definition) {
$this->definitions[$type] = $definition;
protected function loadAllSchema() {
foreach ($this->storage->listAll() as $name) {
if ($schema = $this->storage->read($name)) {
foreach ($schema as $type => $definition) {
$this->definitions[$type] = $definition;
}
}
}
}
......
<?php
/**
* @file
* Contains \Drupal\Core\Config\Schema\SchemaStorage.
*/
namespace Drupal\Core\Config\Schema;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\StorageException;
/**
* Defines the file storage controller for metadata files.
*/
class SchemaStorage extends InstallStorage {
/**
* 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.');
}
}
......@@ -18,19 +18,21 @@ class TypedConfigManager extends TypedDataManager {
/**
* A storage controller instance for reading configuration data.
*
* @var Drupal\Core\Config\StorageInterface
* @var \Drupal\Core\Config\StorageInterface
*/
protected $storage;
protected $configStorage;
/**
* Creates a new typed configuration manager.
*
* @param Drupal\Core\Config\StorageInterface $storage
* @param \Drupal\Core\Config\StorageInterface $configStorage
* The storage controller object to use for reading schema data
* @param \Drupal\Core\Config\StorageInterface $schemaStorage
* The storage controller object to use for reading schema data
*/
public function __construct($storage) {
$this->storage = $storage;
$this->discovery = new SchemaDiscovery($storage);
public function __construct(StorageInterface $configStorage, StorageInterface $schemaStorage) {
$this->configStorage = $configStorage;
$this->discovery = new SchemaDiscovery($schemaStorage);
$this->factory = new TypedConfigElementFactory($this->discovery);
}
......@@ -40,17 +42,17 @@ public function __construct($storage) {
* @param string $name
* Configuration object name.
*
* @return Drupal\Core\Config\Schema\Element
* @return \Drupal\Core\Config\Schema\Element
* Typed configuration element.
*/
public function get($name) {
$data = $this->storage->read($name);
$data = $this->configStorage->read($name);
$definition = $this->getDefinition($name);
return $this->create($definition, $data);
}
/**
* Overrides Drupal\Core\TypedData\TypedDataManager::create()
* Overrides \Drupal\Core\TypedData\TypedDataManager::create()
*
* Fills in default type and does variable replacement.
*/
......
......@@ -68,9 +68,14 @@ public function build(ContainerBuilder $container) {
->addArgument(new Reference('database'))
->addArgument('config_snapshot');
// Register schema configuration storage.
$container
->register('config.storage.schema', 'Drupal\Core\Config\Schema\SchemaStorage');
// Register the typed configuration data manager.
$container->register('config.typed', 'Drupal\Core\Config\TypedConfigManager')
->addArgument(new Reference('config.storage'));
->addArgument(new Reference('config.storage'))
->addArgument(new Reference('config.storage.schema'));
// Register the service for the default database connection.
$container->register('database', 'Drupal\Core\Database\Connection')
......
......@@ -61,44 +61,3 @@ mail:
"body":
type: text
label: "Body"
# Schema for configuration files of system module:
system.site:
type: mapping
label: 'Site information'
mapping:
"name":
label: "Site name"
type: label
"mail":
label: "Site mail"
type: email
"slogan":
label: "Site slogan"
type: text
"page":
type: mapping
mapping:
"403":
type: path
"404":
type: path
"front":
type: path
label: "Front page path"
"admin_compact_mode":
type: boolean
"weight_select_max":
type: integer
system.maintenance:
type: mapping
label: 'Maintenance mode'
mapping:
"enabled":
type: boolean
label: "Put site into maintenance mode"
"message":
type: text
label: "Message to display when in maintenance mode"
# Schema for configuration files of system module:
system.site:
type: mapping
label: 'Site information'
mapping:
"name":
label: "Site name"
type: label
"mail":
label: "Site mail"
type: email
"slogan":
label: "Site slogan"
type: text
"page":
type: mapping
mapping:
"403":
type: path
"404":
type: path
"front":
type: path
label: "Front page path"
"admin_compact_mode":
type: boolean
"weight_select_max":
type: integer
system.maintenance:
type: mapping
label: 'Maintenance mode'
mapping:
"enabled":
type: boolean
label: "Put site into maintenance mode"
"message":
type: text
label: "Message to display when in maintenance mode"
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