abstract class ConfigProviderBase in Configuration Provider 8
Same name and namespace in other branches
- 8.2 src/Plugin/ConfigProviderBase.php \Drupal\config_provider\Plugin\ConfigProviderBase
Base class for Configuration provider plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\config_provider\Plugin\ConfigProviderBase implements ConfigProviderInterface
Expanded class hierarchy of ConfigProviderBase
2 files declare their use of ConfigProviderBase
- ConfigProviderInstall.php in src/
Plugin/ ConfigProvider/ ConfigProviderInstall.php - ConfigProviderOptional.php in src/
Plugin/ ConfigProvider/ ConfigProviderOptional.php
File
- src/
Plugin/ ConfigProviderBase.php, line 14
Namespace
Drupal\config_provider\PluginView source
abstract class ConfigProviderBase extends PluginBase implements ConfigProviderInterface {
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The active configuration storages, keyed by collection.
*
* @var \Drupal\Core\Config\StorageInterface[]
*/
protected $activeStorages;
/**
* The configuration manager.
*
* @var \Drupal\Core\Config\ConfigManagerInterface
*/
protected $configManager;
/**
* {@inheritdoc}
*/
public function providesFullConfig() {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function getDirectory() {
return static::ID;
}
/**
* {@inheritdoc}
*/
public function setConfigFactory(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public function setActiveStorages(StorageInterface $active_storage) {
$this->activeStorages[$active_storage
->getCollectionName()] = $active_storage;
}
/**
* {@inheritdoc}
*/
public function setConfigManager(ConfigManagerInterface $config_manager) {
$this->configManager = $config_manager;
}
/**
* Gets the storage for a designated configuration provider.
*
* @param string $directory
* The configuration directory (for example, config/install).
* @param string $collection
* (optional) The configuration collection. Defaults to the default
* collection.
*
* @return \Drupal\Core\Config\StorageInterface
* The configuration storage that provides the default configuration.
*/
protected function getExtensionInstallStorage($directory, $collection = StorageInterface::DEFAULT_COLLECTION) {
return new ExtensionInstallStorage($this
->getActiveStorages($collection), $directory, $collection);
}
/**
* Gets the configuration storage that provides the active configuration.
*
* @param string $collection
* (optional) The configuration collection. Defaults to the default
* collection.
*
* @return \Drupal\Core\Config\StorageInterface
* The configuration storage that provides the default configuration.
*/
protected function getActiveStorages($collection = StorageInterface::DEFAULT_COLLECTION) {
if (!isset($this->activeStorages[$collection])) {
$this->activeStorages[$collection] = reset($this->activeStorages)
->createCollection($collection);
}
return $this->activeStorages[$collection];
}
/**
* Gets the list of enabled extensions including both modules and themes.
*
* @return array
* A list of enabled extensions which includes both modules and themes.
*/
protected function getEnabledExtensions() {
// Read enabled extensions directly from configuration to avoid circular
// dependencies on ModuleHandler and ThemeHandler.
$extension_config = $this->configFactory
->get('core.extension');
$enabled_extensions = (array) $extension_config
->get('module');
$enabled_extensions += (array) $extension_config
->get('theme');
// Core can provide configuration.
$enabled_extensions['core'] = 'core';
return array_keys($enabled_extensions);
}
/**
* Validates an array of config data that contains dependency information.
*
* @param string $config_name
* The name of the configuration object that is being validated.
* @param array $data
* Configuration data.
* @param array $enabled_extensions
* A list of all the currently enabled modules and themes.
* @param array $all_config
* A list of all the active configuration names.
*
* @return bool
* TRUE if the dependencies are met, FALSE if not.
*/
protected function validateDependencies($config_name, array $data, array $enabled_extensions, array $all_config) {
if (isset($data['dependencies'])) {
$all_dependencies = $data['dependencies'];
// Ensure enforced dependencies are included.
if (isset($all_dependencies['enforced'])) {
$all_dependencies = array_merge($all_dependencies, $data['dependencies']['enforced']);
unset($all_dependencies['enforced']);
}
// Ensure the configuration entity type provider is in the list of
// dependencies.
list($provider) = explode('.', $config_name, 2);
if (!isset($all_dependencies['module'])) {
$all_dependencies['module'][] = $provider;
}
elseif (!in_array($provider, $all_dependencies['module'])) {
$all_dependencies['module'][] = $provider;
}
foreach ($all_dependencies as $type => $dependencies) {
$list_to_check = [];
switch ($type) {
case 'module':
case 'theme':
$list_to_check = $enabled_extensions;
break;
case 'config':
$list_to_check = $all_config;
break;
}
if (!empty($list_to_check)) {
$missing = array_diff($dependencies, $list_to_check);
if (!empty($missing)) {
return FALSE;
}
}
}
}
return TRUE;
}
/**
* Returns a list of all configuration items or those of extensions.
*
* @param \Drupal\Core\Config\StorageInterface $storage
* A configuration storage.
* @param \Drupal\Core\Extension\Extension[] $extensions
* An associative array of Extension objects, keyed by extension name.
*
* @return array
* An array containing configuration object names.
*/
protected function listConfig(StorageInterface $storage, array $extensions = []) {
if (!empty($extensions)) {
$config_names = [];
/* @var \Drupal\Core\Extension\Extension $extension */
foreach ($extensions as $name => $extension) {
$config_names = array_merge($config_names, array_keys($storage
->getComponentNames([
$name => $extension,
])));
}
}
else {
$config_names = $storage
->listAll();
}
return $config_names;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigProviderBase:: |
protected | property | The active configuration storages, keyed by collection. | |
ConfigProviderBase:: |
protected | property | The configuration factory. | |
ConfigProviderBase:: |
protected | property | The configuration manager. | |
ConfigProviderBase:: |
protected | function | Gets the configuration storage that provides the active configuration. | |
ConfigProviderBase:: |
public | function |
Returns the configuration directory. Overrides ConfigProviderInterface:: |
|
ConfigProviderBase:: |
protected | function | Gets the list of enabled extensions including both modules and themes. | |
ConfigProviderBase:: |
protected | function | Gets the storage for a designated configuration provider. | |
ConfigProviderBase:: |
protected | function | Returns a list of all configuration items or those of extensions. | |
ConfigProviderBase:: |
public | function |
Indicates whether the configuration items returned by the provider are
full as opposed to partials. Overrides ConfigProviderInterface:: |
|
ConfigProviderBase:: |
public | function |
Injects the active configuration storage. Overrides ConfigProviderInterface:: |
|
ConfigProviderBase:: |
public | function |
Injects the active configuration storage. Overrides ConfigProviderInterface:: |
|
ConfigProviderBase:: |
public | function |
Injects the active configuration storage. Overrides ConfigProviderInterface:: |
|
ConfigProviderBase:: |
protected | function | Validates an array of config data that contains dependency information. | |
ConfigProviderInterface:: |
public | function | Adds configuration to be installed. | 2 |
ConfigProviderInterface:: |
public | function | Adds configuration that is available to be installed or updated. | 2 |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |