Exemplo n.º 1
0
 /**
  * Creates configuration in a collection based on the provided list.
  *
  * @param string $collection
  *   The configuration collection.
  * @param array $config_to_create
  *   An array of configuration data to create, keyed by name.
  */
 protected function createConfiguration($collection, array $config_to_create)
 {
     // Order the configuration to install in the order of dependencies.
     $config_entity_support = $this->configManager->supportsConfigurationEntities($collection);
     if ($config_entity_support) {
         $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 ($config_entity_support && ($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);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Creates configuration in a collection based on the provided list.
  *
  * @param string $collection
  *   The configuration collection.
  * @param array $config_to_install
  *   A list of configuration object names to create.
  */
 protected function createConfiguration($collection, array $config_to_install)
 {
     // Order the configuration to install in the order of dependencies.
     $data = $this->getSourceStorage($collection)->readMultiple($config_to_install);
     $config_entity_support = $this->configManager->supportsConfigurationEntities($collection);
     if ($config_entity_support) {
         $dependency_manager = new ConfigDependencyManager();
         $config_to_install = $dependency_manager->setData($data)->sortAll();
     }
     // Remove configuration that already exists in the active storage.
     $config_to_install = array_diff($config_to_install, $this->getActiveStorage($collection)->listAll());
     foreach ($config_to_install 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->getActiveStorage($collection), $this->eventDispatcher, $this->typedConfig);
         }
         if ($data[$name] !== FALSE) {
             $new_config->setData($data[$name]);
         }
         if ($config_entity_support && ($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;
             }
             $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->getActiveStorage($collection)->exists($name)) {
                 $id = $entity_storage->getIDFromConfigName($name, $entity_storage->getEntityType()->getConfigPrefix());
                 $entity = $entity_storage->load($id);
                 foreach ($new_config->get() as $property => $value) {
                     $entity->set($property, $value);
                 }
                 $entity->save();
             } else {
                 $entity_storage->create($new_config->get())->save();
             }
         } else {
             $new_config->save();
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Processes a configuration change.
  *
  * @param string $collection
  *   The configuration collection to process changes for.
  * @param string $op
  *   The change operation.
  * @param string $name
  *   The name of the configuration to process.
  *
  * @throws \Exception
  *   Thrown when the import process fails, only thrown when no importer log is
  *   set, otherwise the exception message is logged and the configuration
  *   is skipped.
  */
 protected function processConfiguration($collection, $op, $name)
 {
     try {
         $processed = FALSE;
         if ($this->configManager->supportsConfigurationEntities($collection)) {
             $processed = $this->importInvokeOwner($collection, $op, $name);
         }
         if (!$processed) {
             $this->importConfig($collection, $op, $name);
         }
     } catch (\Exception $e) {
         $this->logError($this->t('Unexpected error during import with operation @op for @name: @message', array('@op' => $op, '@name' => $name, '@message' => $e->getMessage())));
         // Error for that operation was logged, mark it as processed so that
         // the import can continue.
         $this->setProcessedConfiguration($collection, $op, $name);
     }
 }
Exemplo n.º 4
0
 /**
  * Gets and sorts configuration data from the source and target storages.
  */
 protected function getAndSortConfigData($collection)
 {
     $source_storage = $this->getSourceStorage($collection);
     $target_storage = $this->getTargetStorage($collection);
     $target_names = $target_storage->listAll();
     $source_names = $source_storage->listAll();
     $this->targetData[$collection] = $target_storage->readMultiple($target_names);
     $this->sourceData[$collection] = $source_storage->readMultiple($source_names);
     // If the collection only supports simple configuration do not use
     // configuration dependencies.
     if ($this->configManager->supportsConfigurationEntities($collection)) {
         $dependency_manager = new ConfigDependencyManager();
         $this->targetNames[$collection] = $dependency_manager->setData($this->targetData[$collection])->sortAll();
         $this->sourceNames[$collection] = $dependency_manager->setData($this->sourceData[$collection])->sortAll();
     } else {
         $this->targetNames[$collection] = $target_names;
         $this->sourceNames[$collection] = $source_names;
     }
 }