W3cubDocs

/Drupal 8

protected function ConfigInstaller::createConfiguration

protected ConfigInstaller::createConfiguration($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.

File

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

Class

ConfigInstaller

Namespace

Drupal\Core\Config

Code

protected function createConfiguration($collection, array $config_to_create) {
  // Order the configuration to install in the order of dependencies.
  if ($collection == StorageInterface::DEFAULT_COLLECTION) {
    $dependency_manager = new ConfigDependencyManager();
    $config_names = $dependency_manager
    ->setData($config_to_create)
      ->sortAll();
  }
  else {
    $config_names = array_keys($config_to_create);
  }

  foreach ($config_names as $name) {
    // Allow config factory overriders to use a custom configuration object if
    // they are responsible for the collection.
    $overrider = $this->configManager->getConfigCollectionInfo()->getOverrideService($collection);
    if ($overrider) {
      $new_config = $overrider->createConfigObject($name, $collection);
    }
    else {
      $new_config = new Config($name, $this->getActiveStorages($collection), $this->eventDispatcher, $this->typedConfig);
    }
    if ($config_to_create[$name] !== FALSE) {
      $new_config->setData($config_to_create[$name]);
      // Add a hash to configuration created through the installer so it is
      // possible to know if the configuration was created by installing an
      // extension and to track which version of the default config was used.
      if (!$this->isSyncing() && $collection == StorageInterface::DEFAULT_COLLECTION) {
        $new_config->set('_core.default_config_hash', Crypt::hashBase64(serialize($config_to_create[$name])));
      }
    }
    if ($collection == StorageInterface::DEFAULT_COLLECTION && $entity_type = $this->configManager->getEntityTypeIdByName($name)) {
      // If we are syncing do not create configuration entities. Pluggable
      // configuration entities can have dependencies on modules that are
      // not yet enabled. This approach means that any code that expects
      // default configuration entities to exist will be unstable after the
      // module has been enabled and before the config entity has been
      // imported.
      if ($this->isSyncing()) {
        continue;
      }
      /** @var \Drupal\Core\Config\Entity\ConfigEntityStorageInterface $entity_storage */
      $entity_storage = $this->configManager
        ->getEntityManager()
        ->getStorage($entity_type);
      // It is possible that secondary writes can occur during configuration
      // creation. Updates of such configuration are allowed.
      if ($this->getActiveStorages($collection)->exists($name)) {
        $id = $entity_storage->getIDFromConfigName($name, $entity_storage->getEntityType()->getConfigPrefix());
        $entity = $entity_storage->load($id);
        $entity = $entity_storage->updateFromStorageRecord($entity, $new_config->get());
      }
      else {
        $entity = $entity_storage->createFromStorageRecord($new_config->get());
      }
      if ($entity->isInstallable()) {
        $entity->trustData()->save();
      }
    }
    else {
      $new_config->save(TRUE);
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Config!ConfigInstaller.php/function/ConfigInstaller::createConfiguration/8.1.x