class ConfigImporter (View source)

Defines a configuration importer.

A config importer imports the changes into the configuration system. To determine which changes to import a StorageComparer in used.

Traits

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

Provides dependency injection friendly methods for serialization.

Constants

LOCK_NAME

The name used to identify the lock.

Properties

protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected StorageComparerInterface $storageComparer

The storage comparer used to discover configuration changes.

protected EventDispatcherInterface $eventDispatcher

The event dispatcher used to notify subscribers.

protected ConfigManagerInterface $configManager

The configuration manager.

protected LockBackendInterface $lock

The used lock backend instance.

protected TypedConfigManagerInterface $typedConfigManager

The typed config manager.

protected array $processedConfiguration

List of configuration file changes processed by the import().

protected array $processedExtensions

List of extension changes processed by the import().

protected array $extensionChangelist

List of extension changes to be processed by the import().

protected bool $validated

Indicates changes to import have been validated.

protected ModuleHandlerInterface $moduleHandler

The module handler.

protected ThemeHandlerInterface $themeHandler

The theme handler.

protected bool $processedSystemTheme

Flag set to import system.theme during processing theme install and uninstalls.

protected array $errors

A log of any errors encountered.

protected int $totalExtensionsToProcess

The total number of extensions to process.

protected int $totalConfigurationToProcess

The total number of configuration objects to process.

protected ModuleInstallerInterface $moduleInstaller

The module installer.

protected ModuleExtensionList $moduleExtensionList

The module extension list.

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.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(StorageComparerInterface $storage_comparer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, TranslationInterface $string_translation, ModuleExtensionList $extension_list_module)

Constructs a configuration import object.

logError(string $message)

Logs an error message.

array
getErrors()

Returns error messages created while running the import.

getStorageComparer()

Gets the configuration storage comparer.

$this
reset()

Resets the storage comparer and processed list.

array
getEmptyExtensionsProcessedList()

Gets an empty list of extensions to process.

bool
hasUnprocessedConfigurationChanges()

Checks if there are any unprocessed configuration changes.

array
getProcessedConfiguration(string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets list of processed changes.

setProcessedConfiguration(string $collection, string $op, string $name)

Sets a change as processed.

array
getUnprocessedConfiguration(string $op, string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets a list of unprocessed changes for a given operation.

array
getProcessedExtensions()

Gets list of processed extension changes.

setProcessedExtension(string $type, string $op, string $name)

Sets an extension change as processed.

createExtensionChangelist()

Populates the extension change list.

array
getExtensionChangelist(string $type, string $op = NULL)

Gets a list changes for extensions.

array
getUnprocessedExtensions(string $type)

Gets a list of unprocessed changes for extensions.

$this
import()

Imports the changelist to the target storage.

doSyncStep(string|callable $sync_step, array $context)

Calls a config import step.

array
initialize()

Initializes the config importer in preparation for processing a batch.

processExtensions(array|ArrayAccess $context)

Processes extensions as a batch operation.

processConfigurations(array|ArrayAccess $context)

Processes configuration as a batch operation.

processMissingContent(array|ArrayAccess $context)

Handles processing of missing content.

finish(array|ArrayAccess $context)

Finishes the batch.

array|bool
getNextExtensionOperation()

Gets the next extension operation to perform.

array|bool
getNextConfigurationOperation()

Gets the next configuration operation to perform.

validate()

Dispatches validate event for a ConfigImporter object.

processConfiguration(string $collection, string $op, string $name)

Processes a configuration change.

processExtension(string $type, string $op, string $name)

Processes an extension change.

bool
checkOp(string $collection, string $op, string $name)

Checks that the operation is still valid.

importConfig(string $collection, string $op, string $name)

Writes a configuration change from the source to the target storage.

bool
importInvokeOwner(string $collection, string $op, string $name)

Invokes import* methods on configuration entity storage.

bool
importInvokeRename(string $collection, string $rename_name)

Imports a configuration entity rename.

bool
alreadyImporting()

Determines if an import is already running.

reInjectMe()

Gets all the service dependencies from \Drupal.

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

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

__construct(StorageComparerInterface $storage_comparer, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, LockBackendInterface $lock, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, TranslationInterface $string_translation, ModuleExtensionList $extension_list_module)

Constructs a configuration import object.

Parameters

StorageComparerInterface $storage_comparer

A storage comparer object used to determine configuration changes and access the source and target storage objects.

EventDispatcherInterface $event_dispatcher

The event dispatcher used to notify subscribers of config import events.

ConfigManagerInterface $config_manager

The configuration manager.

LockBackendInterface $lock

The lock backend to ensure multiple imports do not occur at the same time.

TypedConfigManagerInterface $typed_config

The typed configuration manager.

ModuleHandlerInterface $module_handler

The module handler

ModuleInstallerInterface $module_installer

The module installer.

ThemeHandlerInterface $theme_handler

The theme handler

TranslationInterface $string_translation

The string translation service.

ModuleExtensionList $extension_list_module

The module extension list.

logError(string $message)

Logs an error message.

Parameters

string $message

The message to log.

array getErrors()

Returns error messages created while running the import.

Return Value

array

List of messages.

StorageComparerInterface getStorageComparer()

Gets the configuration storage comparer.

Return Value

StorageComparerInterface

Storage comparer object used to calculate configuration changes.

$this reset()

Resets the storage comparer and processed list.

Return Value

$this

The ConfigImporter instance.

protected array getEmptyExtensionsProcessedList()

Gets an empty list of extensions to process.

Return Value

array

An empty list of extensions to process.

bool hasUnprocessedConfigurationChanges()

Checks if there are any unprocessed configuration changes.

Return Value

bool

TRUE if there are changes to process and FALSE if not.

array getProcessedConfiguration(string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets list of processed changes.

Parameters

string $collection

(optional) The configuration collection to get processed changes for. Defaults to the default collection.

Return Value

array

An array containing a list of processed changes.

protected setProcessedConfiguration(string $collection, string $op, string $name)

Sets a change as processed.

Parameters

string $collection

The configuration collection to set a change as processed for.

string $op

The change operation performed, either delete, create, rename, or update.

string $name

The name of the configuration processed.

array getUnprocessedConfiguration(string $op, string $collection = StorageInterface::DEFAULT_COLLECTION)

Gets a list of unprocessed changes for a given operation.

Parameters

string $op

The change operation to get the unprocessed list for, either delete, create, rename, or update.

string $collection

(optional) The configuration collection to get unprocessed changes for. Defaults to the default collection.

Return Value

array

An array of configuration names.

array getProcessedExtensions()

Gets list of processed extension changes.

Return Value

array

An array containing a list of processed extension changes.

protected setProcessedExtension(string $type, string $op, string $name)

Sets an extension change as processed.

Parameters

string $type

The type of extension, either 'theme' or 'module'.

string $op

The change operation performed, either install or uninstall.

string $name

The name of the extension processed.

protected createExtensionChangelist()

Populates the extension change list.

array getExtensionChangelist(string $type, string $op = NULL)

Gets a list changes for extensions.

Parameters

string $type

The type of extension, either 'theme' or 'module'.

string $op

The change operation to get the unprocessed list for, either install or uninstall.

Return Value

array

An array of extension names.

protected array getUnprocessedExtensions(string $type)

Gets a list of unprocessed changes for extensions.

Parameters

string $type

The type of extension, either 'theme' or 'module'.

Return Value

array

An array of extension names.

$this import()

Imports the changelist to the target storage.

Return Value

$this

The ConfigImporter instance.

Exceptions

ConfigException

doSyncStep(string|callable $sync_step, array $context)

Calls a config import step.

Parameters

string|callable $sync_step

The step to do. Either a method on the ConfigImporter class or a callable.

array $context

A batch context array. If the config importer is not running in a batch the only array key that is used is $context['finished']. A process needs to set $context['finished'] = 1 when it is done.

Exceptions

InvalidArgumentException

array initialize()

Initializes the config importer in preparation for processing a batch.

Return Value

array

An array of \Drupal\Core\Config\ConfigImporter method names and callables that are invoked to complete the import. If there are modules or themes to process then an extra step is added.

Exceptions

ConfigImporterException

protected processExtensions(array|ArrayAccess $context)

Processes extensions as a batch operation.

Parameters

array|ArrayAccess $context

The batch context.

protected processConfigurations(array|ArrayAccess $context)

Processes configuration as a batch operation.

Parameters

array|ArrayAccess $context

The batch context.

protected processMissingContent(array|ArrayAccess $context)

Handles processing of missing content.

Parameters

array|ArrayAccess $context

Standard batch context.

protected finish(array|ArrayAccess $context)

Finishes the batch.

Parameters

array|ArrayAccess $context

The batch context.

protected array|bool getNextExtensionOperation()

Gets the next extension operation to perform.

Return Value

array|bool

An array containing the next operation and extension name to perform it on. If there is nothing left to do returns FALSE;

protected array|bool getNextConfigurationOperation()

Gets the next configuration operation to perform.

Return Value

array|bool

An array containing the next operation and configuration name to perform it on. If there is nothing left to do returns FALSE;

validate()

Dispatches validate event for a ConfigImporter object.

Events should throw a \Drupal\Core\Config\ConfigImporterException to prevent an import from occurring.

protected processConfiguration(string $collection, string $op, string $name)

Processes a configuration change.

Parameters

string $collection

The configuration collection to process changes for.

string $op

The change operation.

string $name

The name of the configuration to process.

Exceptions

Exception

protected processExtension(string $type, string $op, string $name)

Processes an extension change.

Parameters

string $type

The type of extension, either 'module' or 'theme'.

string $op

The change operation.

string $name

The name of the extension to process.

protected bool checkOp(string $collection, string $op, string $name)

Checks that the operation is still valid.

During a configuration import secondary writes and deletes are possible. This method checks that the operation is still valid before processing a configuration change.

Parameters

string $collection

The configuration collection.

string $op

The change operation.

string $name

The name of the configuration to process.

Return Value

bool

TRUE is to continue processing, FALSE otherwise.

Exceptions

ConfigImporterException

protected importConfig(string $collection, string $op, string $name)

Writes a configuration change from the source to the target storage.

Parameters

string $collection

The configuration collection.

string $op

The change operation.

string $name

The name of the configuration to process.

protected bool importInvokeOwner(string $collection, string $op, string $name)

Invokes import* methods on configuration entity storage.

Allow modules to take over configuration change operations for higher-level configuration data.

Add support for other extension types; e.g., themes etc.

Parameters

string $collection

The configuration collection.

string $op

The change operation to get the unprocessed list for, either delete, create, rename, or update.

string $name

The name of the configuration to process.

Return Value

bool

TRUE if the configuration was imported as a configuration entity. FALSE otherwise.

Exceptions

EntityStorageException

protected bool importInvokeRename(string $collection, string $rename_name)

Imports a configuration entity rename.

Parameters

string $collection

The configuration collection.

string $rename_name

The rename configuration name, as provided by \Drupal\Core\Config\StorageComparer::createRenameName().

Return Value

bool

TRUE if the configuration was imported as a configuration entity. FALSE otherwise.

Exceptions

EntityStorageException

See also

\Drupal\Core\Config\ConfigImporter::createRenameName()

bool alreadyImporting()

Determines if an import is already running.

Return Value

bool

TRUE if an import is already running, FALSE if not.

protected reInjectMe()

Gets all the service dependencies from \Drupal.

Since the ConfigImporter handles module installation the kernel and the container can be rebuilt and altered during processing. It is necessary to keep the services used by the importer in sync.