You are here

protected function FeaturesConfigInstaller::findPreExistingConfiguration in Features 8.3

Same name and namespace in other branches
  1. 8.4 src/FeaturesConfigInstaller.php \Drupal\features\FeaturesConfigInstaller::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.

Return value

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

Overrides ConfigInstaller::findPreExistingConfiguration

File

src/FeaturesConfigInstaller.php, line 64

Class

FeaturesConfigInstaller
Class for customizing the test for pre existing configuration.

Namespace

Drupal\features

Code

protected function findPreExistingConfiguration(StorageInterface $storage) {

  // Override
  // Drupal\Core\Config\ConfigInstaller::findPreExistingConfiguration().
  // Allow config that already exists coming from Features.
  $features_config = array_keys($this->featuresManager
    ->listExistingConfig());

  // Map array so we can use isset instead of in_array for faster access.
  $features_config = array_combine($features_config, $features_config);
  $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)) {

        // Test if config is part of a Feature package.
        if (!isset($features_config[$config_name])) {
          $existing_configuration[$collection][] = $config_name;
        }
      }
    }
  }
  return $existing_configuration;
}