You are here

public function FeaturesManager::createConfiguration in Features 8.4

Same name and namespace in other branches
  1. 8.3 src/FeaturesManager.php \Drupal\features\FeaturesManager::createConfiguration()

Creates configuration in a collection based on the provided list.

Parameters

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

Return value

array of config imported 'new': list of new config created keyed by name. 'updated': list of updated config keyed by name.

Overrides FeaturesManagerInterface::createConfiguration

1 call to FeaturesManager::createConfiguration()
FeaturesManager::import in src/FeaturesManager.php
The import function.

File

src/FeaturesManager.php, line 1420

Class

FeaturesManager
The FeaturesManager provides helper functions for building packages.

Namespace

Drupal\features

Code

public function createConfiguration(array $config_to_create) {
  $existing_config = $this
    ->getConfigCollection();

  // If config data is not specified, load it from the extension storage.
  foreach ($config_to_create as $name => $item) {
    if (empty($item)) {
      $config = $this->configReverter
        ->getFromExtension('', $name);

      // For testing purposes, if it couldn't load from a module, get config
      // from the cached Config Collection.
      if (empty($config) && isset($existing_config[$name])) {
        $config = $existing_config[$name]
          ->getData();
      }
      $config_to_create[$name] = $config;
    }
  }

  // Determine which config is new vs existing.
  $existing = array_intersect_key($config_to_create, $existing_config);
  $new = array_diff_key($config_to_create, $existing);

  // The FeaturesConfigInstaller exposes the normally protected
  // createConfiguration
  // function from Core ConfigInstaller than handles the creation of new
  // config or the changing of existing config.

  /** @var \Drupal\features\FeaturesConfigInstaller $config_installer */
  $config_installer = \Drupal::service('features.config.installer');
  $config_installer
    ->createConfiguration(StorageInterface::DEFAULT_COLLECTION, $config_to_create);

  // Collect results for new and updated config.
  $new_config = $this
    ->getConfigCollection(TRUE);
  $result['updated'] = array_intersect_key($new_config, $existing);
  $result['new'] = array_intersect_key($new_config, $new);
  return $result;
}