function ConfigInstaller::findPreExistingConfiguration

Same name in other branches
  1. 9 core/lib/Drupal/Core/Config/ConfigInstaller.php \Drupal\Core\Config\ConfigInstaller::findPreExistingConfiguration()
  2. 8.9.x core/lib/Drupal/Core/Config/ConfigInstaller.php \Drupal\Core\Config\ConfigInstaller::findPreExistingConfiguration()
  3. 10 core/lib/Drupal/Core/Config/ConfigInstaller.php \Drupal\Core\Config\ConfigInstaller::findPreExistingConfiguration()

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

\Drupal\Core\Config\StorageInterface $storage: The storage containing the default configuration.

array $previous_config_names: An array of configuration names that have previously been checked.

Return value

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

1 call to ConfigInstaller::findPreExistingConfiguration()
ConfigInstaller::checkConfigurationToInstall in core/lib/Drupal/Core/Config/ConfigInstaller.php
Checks the configuration that will be installed for an extension.

File

core/lib/Drupal/Core/Config/ConfigInstaller.php, line 527

Class

ConfigInstaller

Namespace

Drupal\Core\Config

Code

protected function findPreExistingConfiguration(StorageInterface $storage, array $previous_config_names = []) {
    $existing_configuration = [];
    // Gather information about all the supported collections.
    $collection_info = $this->configManager
        ->getConfigCollectionInfo();
    foreach ($collection_info->getCollectionNames() as $collection) {
        $config_to_create = array_keys($this->getConfigToCreate($storage, $collection));
        $active_storage = $this->getActiveStorages($collection);
        foreach ($config_to_create as $config_name) {
            if ($active_storage->exists($config_name) || array_search($config_name, $previous_config_names[$collection] ?? [], TRUE) !== FALSE) {
                $existing_configuration[$collection][] = $config_name;
            }
        }
    }
    return $existing_configuration;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.