class ConfigInstaller implements ConfigInstallerInterface (View source)

Properties

protected ConfigFactoryInterface $configFactory

The configuration factory.

protected StorageInterface[] $activeStorages

The active configuration storages, keyed by collection.

protected TypedConfigManagerInterface $typedConfig

The typed configuration manager.

protected ConfigManagerInterface $configManager

The configuration manager.

protected EventDispatcherInterface $eventDispatcher

The event dispatcher.

protected StorageInterface $sourceStorage

The configuration storage that provides the default configuration.

protected bool $isSyncing

Is configuration being created as part of a configuration sync.

protected string $installProfile

The name of the currently active installation profile.

Methods

__construct(ConfigFactoryInterface $config_factory, StorageInterface $active_storage, TypedConfigManagerInterface $typed_config, ConfigManagerInterface $config_manager, EventDispatcherInterface $event_dispatcher, string $install_profile)

Constructs the configuration installer.

installDefaultConfig(string $type, string $name)

Installs the default configuration of a given extension.

installOptionalConfig(StorageInterface $storage = NULL, array $dependency = [])

Installs optional configuration.

array
getConfigToCreate(StorageInterface $storage, string $collection, string $prefix = '', array $profile_storages = [])

Gets configuration data from the provided storage to create.

createConfiguration(string $collection, array $config_to_create)

Creates configuration in a collection based on the provided list.

installCollectionDefaultConfig(string $collection)

Installs all default configuration in the specified collection.

$this
setSourceStorage(StorageInterface $storage)

Sets the configuration storage that provides the default configuration.

getSourceStorage()

Gets the configuration storage that provides the default configuration.

getActiveStorages(string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets the configuration storage that provides the active configuration.

$this
setSyncing(bool $status)

Sets the status of the isSyncing flag.

bool
isSyncing()

Gets the syncing state.

array
findPreExistingConfiguration(StorageInterface $storage)

Finds pre-existing configuration objects for the provided extension.

checkConfigurationToInstall(string $type, string $name)

Checks the configuration that will be installed for an extension.

array
findDefaultConfigWithUnmetDependencies(StorageInterface $storage, array $enabled_extensions, array $profile_storages = [])

Finds default configuration with unmet dependencies.

bool
validateDependencies(string $config_name, array $data, array $enabled_extensions, array $all_config)

Validates an array of config data that contains dependency information.

array
getMissingDependencies(string $config_name, array $data, array $enabled_extensions, array $all_config)

Returns an array of missing dependencies for a config object.

array
getEnabledExtensions()

Gets the list of enabled extensions including both modules and themes.

getProfileStorages(string $installing_name = '')

Gets the profile storage to use to check for profile overrides.

string
getDefaultConfigDirectory(string $type, string $name)

Gets an extension's default configuration directory.

string
drupalGetPath($type, $name)

Wrapper for drupal_get_path().

string|null
drupalGetProfile()

Gets the install profile from settings.

bool
drupalInstallationAttempted() deprecated

Wrapper for drupal_installation_attempted().

Details

__construct(ConfigFactoryInterface $config_factory, StorageInterface $active_storage, TypedConfigManagerInterface $typed_config, ConfigManagerInterface $config_manager, EventDispatcherInterface $event_dispatcher, string $install_profile)

Constructs the configuration installer.

Parameters

ConfigFactoryInterface $config_factory

The configuration factory.

StorageInterface $active_storage

The active configuration storage.

TypedConfigManagerInterface $typed_config

The typed configuration manager.

ConfigManagerInterface $config_manager

The configuration manager.

EventDispatcherInterface $event_dispatcher

The event dispatcher.

string $install_profile

The name of the currently active installation profile.

installDefaultConfig(string $type, string $name)

Installs the default configuration of a given extension.

When an extension is installed, it searches all the default configuration directories for all other extensions to locate any configuration with its name prefix. For example, the Node module provides the frontpage view as a default configuration file: core/modules/node/config/install/views.view.frontpage.yml When the Views module is installed after the Node module is already enabled, the frontpage view will be installed.

Additionally, the default configuration directory for the extension being installed is searched to discover if it contains default configuration that is owned by other enabled extensions. So, the frontpage view will also be installed when the Node module is installed after Views.

Parameters

string $type

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

string $name

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

installOptionalConfig(StorageInterface $storage = NULL, array $dependency = [])

Installs optional configuration.

Optional configuration is only installed if:

  • the configuration does not exist already.
  • it's a configuration entity.
  • its dependencies can be met.

Parameters

StorageInterface $storage

(optional) The configuration storage to search for optional configuration. If not provided, all enabled extension's optional configuration directories including the install profile's will be searched.

array $dependency

(optional) If set, ensures that the configuration being installed has this dependency. The format is dependency type as the key ('module', 'theme', or 'config') and the dependency name as the value ('book', 'bartik', 'views.view.frontpage').

protected array getConfigToCreate(StorageInterface $storage, string $collection, string $prefix = '', array $profile_storages = [])

Gets configuration data from the provided storage to create.

Parameters

StorageInterface $storage

The configuration storage to read configuration from.

string $collection

The configuration collection to use.

string $prefix

(optional) Limit to configuration starting with the provided string.

array $profile_storages

An array of storage interfaces containing profile configuration to check for overrides.

Return Value

array

An array of configuration data read from the source storage keyed by the configuration object name.

protected createConfiguration(string $collection, array $config_to_create)

Creates configuration in a collection based on the provided list.

Parameters

string $collection

The configuration collection.

array $config_to_create

An array of configuration data to create, keyed by name.

installCollectionDefaultConfig(string $collection)

Installs all default configuration in the specified collection.

The function is useful if the site needs to respond to an event that has just created another collection and we need to check all the installed extensions for any matching configuration. For example, if a language has just been created.

Parameters

string $collection

The configuration collection.

$this setSourceStorage(StorageInterface $storage)

Sets the configuration storage that provides the default configuration.

Parameters

StorageInterface $storage

Return Value

$this

StorageInterface|null getSourceStorage()

Gets the configuration storage that provides the default configuration.

Return Value

StorageInterface|null

The configuration storage that provides the default configuration. Returns null if the source storage has not been set.

protected StorageInterface getActiveStorages(string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets the configuration storage that provides the active configuration.

Parameters

string $collection

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

Return Value

StorageInterface

The configuration storage that provides the default configuration.

$this setSyncing(bool $status)

Sets the status of the isSyncing flag.

Parameters

bool $status

The status of the sync flag.

Return Value

$this

bool isSyncing()

Gets the syncing state.

Return Value

bool

Returns TRUE is syncing flag set.

protected array findPreExistingConfiguration(StorageInterface $storage)

Finds pre-existing configuration objects for the provided extension.

Extensions can not be installed if configuration objects exist in the active storage with the same names. This can happen in a number of ways, commonly:

  • if a user has created configuration with the same name as that provided by the extension.
  • if the extension provides default configuration that does not depend on it and the extension has been uninstalled and is about to the reinstalled.

Parameters

StorageInterface $storage

Return Value

array

Array of configuration object names that already exist keyed by collection.

checkConfigurationToInstall(string $type, string $name)

Checks the configuration that will be installed for an extension.

Parameters

string $type

Type of extension to install.

string $name

Name of extension to install.

Exceptions

UnmetDependenciesException
PreExistingConfigException

protected array findDefaultConfigWithUnmetDependencies(StorageInterface $storage, array $enabled_extensions, array $profile_storages = [])

Finds default configuration with unmet dependencies.

Parameters

StorageInterface $storage

The storage containing the default configuration.

array $enabled_extensions

A list of all the currently enabled modules and themes.

array $profile_storages

An array of storage interfaces containing profile configuration to check for overrides.

Return Value

array

An array containing:

  • A list of configuration that has unmet dependencies.
  • An array that will be filled with the missing dependency names, keyed by the dependents' names.

protected bool validateDependencies(string $config_name, array $data, array $enabled_extensions, array $all_config)

Validates an array of config data that contains dependency information.

Parameters

string $config_name

The name of the configuration object that is being validated.

array $data

Configuration data.

array $enabled_extensions

A list of all the currently enabled modules and themes.

array $all_config

A list of all the active configuration names.

Return Value

bool

TRUE if all dependencies are present, FALSE otherwise.

protected array getMissingDependencies(string $config_name, array $data, array $enabled_extensions, array $all_config)

Returns an array of missing dependencies for a config object.

Parameters

string $config_name

The name of the configuration object that is being validated.

array $data

Configuration data.

array $enabled_extensions

A list of all the currently enabled modules and themes.

array $all_config

A list of all the active configuration names.

Return Value

array

A list of missing config dependencies.

protected array getEnabledExtensions()

Gets the list of enabled extensions including both modules and themes.

Return Value

array

A list of enabled extensions which includes both modules and themes.

protected StorageInterface[]|null getProfileStorages(string $installing_name = '')

Gets the profile storage to use to check for profile overrides.

The install profile can override module configuration during a module install. Both the install and optional directories are checked for matching configuration. This allows profiles to override default configuration for modules they do not depend on.

Parameters

string $installing_name

(optional) The name of the extension currently being installed.

Return Value

StorageInterface[]|null

Storages to access configuration from the installation profile. If we're installing the profile itself, then it will return an empty array as the profile storage should not be used.

protected string getDefaultConfigDirectory(string $type, string $name)

Gets an extension's default configuration directory.

Parameters

string $type

Type of extension to install.

string $name

Name of extension to install.

Return Value

string

The extension's default configuration directory.

protected string drupalGetPath($type, $name)

Wrapper for drupal_get_path().

Parameters

$type

The type of the item; one of 'core', 'profile', 'module', 'theme', or 'theme_engine'.

$name

The name of the item for which the path is requested. Ignored for $type 'core'.

Return Value

string

The path to the requested item or an empty string if the item is not found.

protected string|null drupalGetProfile()

Gets the install profile from settings.

Return Value

string|null

The name of the installation profile or NULL if no installation profile is currently active. This is the case for example during the first steps of the installer or during unit tests.

protected bool drupalInstallationAttempted() deprecated

deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal\Core\Installer\InstallerKernel::installationAttempted() instead.

Wrapper for drupal_installation_attempted().

Return Value

bool

TRUE if a Drupal installation is currently being attempted.

See also

https://www.drupal.org/node/3052704
InstallerKernel::installationAttempted