class ConfigProviderOptional in Configuration Provider 8
Same name and namespace in other branches
- 8.2 src/Plugin/ConfigProvider/ConfigProviderOptional.php \Drupal\config_provider\Plugin\ConfigProvider\ConfigProviderOptional
Class for providing configuration from an install directory.
Plugin annotation
@ConfigProvider(
id = \Drupal\config_provider\Plugin\ConfigProvider\ConfigProviderOptional::ID,
weight = 10,
label = @Translation("Optional"),
description = @Translation("Configuration to be installed when an extension is installed."),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\config_provider\Plugin\ConfigProviderBase implements ConfigProviderInterface
- class \Drupal\config_provider\Plugin\ConfigProvider\ConfigProviderOptional
- class \Drupal\config_provider\Plugin\ConfigProviderBase implements ConfigProviderInterface
Expanded class hierarchy of ConfigProviderOptional
File
- src/
Plugin/ ConfigProvider/ ConfigProviderOptional.php, line 22
Namespace
Drupal\config_provider\Plugin\ConfigProviderView source
class ConfigProviderOptional extends ConfigProviderBase {
/**
* The configuration provider ID.
*/
const ID = InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
/**
* {@inheritdoc}
*/
public function addConfigToCreate(array &$config_to_create, StorageInterface $storage, $collection, $prefix = '', array $profile_storages = []) {
// Optional configuration is installed subsequently, so we can't add it
// here.
}
/**
* {@inheritdoc}
*/
public function addInstallableConfig(InMemoryStorage $installable_config, array $extensions = []) {
// This method is adapted from ConfigInstaller::installOptionalConfig().
// Non-default configuration collections are not supported for
// config/optional.
$storage = $this
->getExtensionInstallStorage(static::ID);
$enabled_extensions = $this
->getEnabledExtensions();
$existing_config = $this
->getActiveStorages()
->listAll();
$list = $this
->listConfig($storage, $extensions);
$list = array_filter($list, function ($config_name) use ($existing_config) {
// Only list configuration that:
// - does not already exist
// - is a configuration entity (this also excludes config that has an
// implicit dependency on modules that are not yet installed)
return !in_array($config_name, $existing_config) && $this->configManager
->getEntityTypeIdByName($config_name);
});
$all_config = array_merge($existing_config, $list);
// Merge in the configuration provided already by previous config
// providers.
$all_config = array_merge($all_config, $installable_config
->listAll());
$all_config = array_combine($all_config, $all_config);
$config_to_create = $storage
->readMultiple($list);
// Sort $config_to_create in the order of the least dependent first.
$dependency_manager = new ConfigDependencyManager();
$dependency_manager
->setData($config_to_create);
$config_to_create = array_merge(array_flip($dependency_manager
->sortAll()), $config_to_create);
foreach ($config_to_create as $config_name => $data) {
// Remove configuration where its dependencies cannot be met.
$remove = !$this
->validateDependencies($config_name, $data, $enabled_extensions, $all_config);
// If $dependency is defined, remove configuration that does not have a
// matching dependency.
if (!$remove && !empty($dependency)) {
// Create a light weight dependency object to check dependencies.
$config_entity = new ConfigEntityDependency($config_name, $data);
$remove = !$config_entity
->hasDependency(key($dependency), reset($dependency));
}
if ($remove) {
// Remove from the list of configuration to create.
unset($config_to_create[$config_name]);
// Remove from the list of all configuration. This ensures that any
// configuration that depends on this configuration is also removed.
unset($all_config[$config_name]);
}
else {
$installable_config
->write($config_name, $data);
}
}
}
}
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. | |
ConfigProviderOptional:: |
public | function |
Adds configuration to be installed. Overrides ConfigProviderInterface:: |
|
ConfigProviderOptional:: |
public | function |
Adds configuration that is available to be installed or updated. Overrides ConfigProviderInterface:: |
|
ConfigProviderOptional:: |
constant | The configuration provider ID. | ||
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 |