You are here

protected function ConfigInstaller::createConfiguration in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Config/ConfigInstaller.php \Drupal\Core\Config\ConfigInstaller::createConfiguration()

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.

3 calls to ConfigInstaller::createConfiguration()
ConfigInstaller::installCollectionDefaultConfig in core/lib/Drupal/Core/Config/ConfigInstaller.php
Installs all default configuration in the specified collection.
ConfigInstaller::installDefaultConfig in core/lib/Drupal/Core/Config/ConfigInstaller.php
Installs the default configuration of a given extension.
ConfigInstaller::installOptionalConfig in core/lib/Drupal/Core/Config/ConfigInstaller.php
Installs optional configuration.

File

core/lib/Drupal/Core/Config/ConfigInstaller.php, line 258
Contains \Drupal\Core\Config\ConfigInstaller.

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]);
    }
    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);
    }
  }
}