class ConfigManager implements ConfigManagerInterface (View source)

The ConfigManager provides helper functions for the configuration system.

Traits

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Utility trait to copy configuration from one storage to another.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

protected EntityRepositoryInterface $entityRepository

The entity repository.

protected ConfigFactoryInterface $configFactory

The configuration factory.

protected TypedConfigManagerInterface $typedConfigManager

The typed config manager.

protected StorageInterface $activeStorage

The active configuration storage.

protected EventDispatcherInterface $eventDispatcher

The event dispatcher.

protected ConfigCollectionInfo $configCollectionInfo

The configuration collection info.

protected StorageInterface[] $storages

The configuration storages keyed by collection name.

Methods

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

static 
replaceStorageContents(StorageInterface $source, StorageInterface $target)

Copy the configuration from one storage to another and remove stale items.

__construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config_manager, TranslationInterface $string_translation, StorageInterface $active_storage, EventDispatcherInterface $event_dispatcher, EntityRepositoryInterface $entity_repository)

Creates ConfigManager objects.

string|null
getEntityTypeIdByName(string $name)

Returns the entity type of a configuration object.

loadConfigEntityByName(string $name)

Loads a configuration entity using the configuration name.

getEntityTypeManager()

Gets the entity type manager.

getConfigFactory()

Gets the config factory.

diff(StorageInterface $source_storage, StorageInterface $target_storage, string $source_name, string $target_name = NULL, string $collection = StorageInterface::DEFAULT_COLLECTION)

Creates a Diff object using the config data from the two storages.

createSnapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage)

Creates a configuration snapshot following a successful import.

uninstall(string $type, string $name)

Uninstalls the configuration of a given extension.

getConfigDependencyManager()

Creates and populates a ConfigDependencyManager object.

findConfigEntityDependents(string $type, array $names, ConfigDependencyManager $dependency_manager = NULL)

Finds config entities that are dependent on extensions or entities.

findConfigEntityDependentsAsEntities(string $type, array $names, ConfigDependencyManager $dependency_manager = NULL)

Finds config entities that are dependent on extensions or entities.

array
getConfigEntitiesToChangeOnDependencyRemoval(string $type, array $names, bool $dry_run = TRUE)

Lists which config entities to update and delete on removal of a dependency.

getConfigCollectionInfo()

Gets available collection information using the event system.

bool
callOnDependencyRemoval(ConfigEntityInterface $entity, array $dependent_entities, string $type, array $names)

Calls an entity's onDependencyRemoval() method.

array
findMissingContentDependencies()

Finds missing content dependencies declared in configuration entities.

Details

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

static protected replaceStorageContents(StorageInterface $source, StorageInterface $target)

Copy the configuration from one storage to another and remove stale items.

This method empties target storage and copies all collections from source. Configuration is only copied and not imported, should not be used with the active storage as the target.

Parameters

StorageInterface $source

The configuration storage to copy from.

StorageInterface $target

The configuration storage to copy to.

__construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config_manager, TranslationInterface $string_translation, StorageInterface $active_storage, EventDispatcherInterface $event_dispatcher, EntityRepositoryInterface $entity_repository)

Creates ConfigManager objects.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

ConfigFactoryInterface $config_factory

The configuration factory.

TypedConfigManagerInterface $typed_config_manager

The typed config manager.

TranslationInterface $string_translation

The string translation service.

StorageInterface $active_storage

The active configuration storage.

EventDispatcherInterface $event_dispatcher

The event dispatcher.

EntityRepositoryInterface $entity_repository

The entity repository.

string|null getEntityTypeIdByName(string $name)

Returns the entity type of a configuration object.

Parameters

string $name

The configuration object name.

Return Value

string|null

Either the entity type name, or NULL if none match.

EntityInterface|null loadConfigEntityByName(string $name)

Loads a configuration entity using the configuration name.

Parameters

string $name

The configuration object name.

Return Value

EntityInterface|null

The configuration entity or NULL if it does not exist.

EntityTypeManagerInterface getEntityTypeManager()

Gets the entity type manager.

Return Value

EntityTypeManagerInterface

The entity type manager.

ConfigFactoryInterface getConfigFactory()

Gets the config factory.

Return Value

ConfigFactoryInterface

The config factory.

Diff diff(StorageInterface $source_storage, StorageInterface $target_storage, string $source_name, string $target_name = NULL, string $collection = StorageInterface::DEFAULT_COLLECTION)

Creates a Diff object using the config data from the two storages.

Parameters

StorageInterface $source_storage

The storage to diff configuration from.

StorageInterface $target_storage

The storage to diff configuration to.

string $source_name

The name of the configuration object in the source storage to diff.

string $target_name

(optional) The name of the configuration object in the target storage. If omitted, the source name is used.

string $collection

(optional) The configuration collection name. Defaults to the default collection.

Return Value

Diff

A Diff object using the config data from the two storages.

createSnapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage)

Creates a configuration snapshot following a successful import.

Parameters

StorageInterface $source_storage

The storage to synchronize configuration from.

StorageInterface $snapshot_storage

The storage to synchronize configuration to.

uninstall(string $type, string $name)

Uninstalls the configuration of a given extension.

Parameters

string $type

The extension type; e.g., 'module' or 'theme'.

string $name

The name of the module or theme to install configuration for.

ConfigDependencyManager getConfigDependencyManager()

Creates and populates a ConfigDependencyManager object.

The configuration dependency manager is populated with data from the active store.

ConfigEntityDependency[] findConfigEntityDependents(string $type, array $names, ConfigDependencyManager $dependency_manager = NULL)

Finds config entities that are dependent on extensions or entities.

Parameters

string $type

The type of dependency being checked. Either 'module', 'theme', 'config' or 'content'.

array $names

The specific names to check. If $type equals 'module' or 'theme' then it should be a list of module names or theme names. In the case of 'config' or 'content' it should be a list of configuration dependency names.

ConfigDependencyManager $dependency_manager

Return Value

ConfigEntityDependency[]

An array of configuration entity dependency objects.

ConfigEntityInterface[] findConfigEntityDependentsAsEntities(string $type, array $names, ConfigDependencyManager $dependency_manager = NULL)

Finds config entities that are dependent on extensions or entities.

Parameters

string $type

The type of dependency being checked. Either 'module', 'theme', 'config' or 'content'.

array $names

The specific names to check. If $type equals 'module' or 'theme' then it should be a list of module names or theme names. In the case of 'config' or 'content' it should be a list of configuration dependency names.

ConfigDependencyManager $dependency_manager

Return Value

ConfigEntityInterface[]

An array of dependencies as configuration entities.

array getConfigEntitiesToChangeOnDependencyRemoval(string $type, array $names, bool $dry_run = TRUE)

Lists which config entities to update and delete on removal of a dependency.

Parameters

string $type

The type of dependency being checked. Either 'module', 'theme', 'config' or 'content'.

array $names

The specific names to check. If $type equals 'module' or 'theme' then it should be a list of module names or theme names. In the case of 'config' or 'content' it should be a list of configuration dependency names.

bool $dry_run

If set to FALSE the entities returned in the list of updates will be modified. In order to make the changes the caller needs to save them. If set to TRUE the entities returned will not be modified.

Return Value

array

An array with the keys: 'update', 'delete' and 'unchanged'. The value of each is a list of configuration entities that need to have that action applied when the supplied dependencies are removed. Updates need to be processed before deletes. The order of the deletes is significant and must be processed in the returned order.

ConfigCollectionInfo getConfigCollectionInfo()

Gets available collection information using the event system.

Return Value

ConfigCollectionInfo

The object which contains information about the available collections.

protected bool callOnDependencyRemoval(ConfigEntityInterface $entity, array $dependent_entities, string $type, array $names)

Calls an entity's onDependencyRemoval() method.

A helper method to call onDependencyRemoval() with the correct list of affected entities. This list should only contain dependencies on the entity. Configuration and content entity dependencies will be converted into entity objects.

Parameters

ConfigEntityInterface $entity

The entity to call onDependencyRemoval() on.

array $dependent_entities

The list of dependent configuration entities.

string $type

The type of dependency being checked. Either 'module', 'theme', 'config' or 'content'.

array $names

The specific names to check. If $type equals 'module' or 'theme' then it should be a list of module names or theme names. In the case of 'config' or 'content' it should be a list of configuration dependency names.

Return Value

bool

TRUE if the entity has changed as a result of calling the onDependencyRemoval() method, FALSE if not.

array findMissingContentDependencies()

Finds missing content dependencies declared in configuration entities.

Return Value

array

A list of missing content dependencies. The array is keyed by UUID. Each value is an array with the following keys: 'entity_type', 'bundle' and 'uuid'.