ConfigImporter::importInvokeRename

protected ConfigImporter::importInvokeRename($collection, $rename_name)

Imports a configuration entity rename.

Parameters

string $collection: The configuration collection.

string $rename_name: The rename configuration name, as provided by \Drupal\Core\Config\StorageComparer::createRenameName().

Return value

bool TRUE if the configuration was imported as a configuration entity. FALSE otherwise.

Throws

\Drupal\Core\Entity\EntityStorageException Thrown if the data is owned by an entity type, but the entity storage does not support imports.

See also

\Drupal\Core\Config\ConfigImporter::createRenameName()

File

core/lib/Drupal/Core/Config/ConfigImporter.php, line 997

Class

ConfigImporter
Defines a configuration importer.

Namespace

Drupal\Core\Config

Code

protected function importInvokeRename($collection, $rename_name) {
  $names = $this->storageComparer->extractRenameNames($rename_name);
  $entity_type_id = $this->configManager->getEntityTypeIdByName($names['old_name']);
  $old_config = new Config($names['old_name'], $this->storageComparer->getTargetStorage($collection), $this->eventDispatcher, $this->typedConfigManager);
  if ($old_data = $this->storageComparer->getTargetStorage($collection)->read($names['old_name'])) {
    $old_config->initWithData($old_data);
  }

  $data = $this->storageComparer->getSourceStorage($collection)->read($names['new_name']);
  $new_config = new Config($names['new_name'], $this->storageComparer->getTargetStorage($collection), $this->eventDispatcher, $this->typedConfigManager);
  if ($data !== FALSE) {
    $new_config->setData($data);
  }

  $entity_storage = $this->configManager->getEntityManager()->getStorage($entity_type_id);
  // Call to the configuration entity's storage to handle the configuration
  // change.
  if (!($entity_storage instanceof ImportableEntityStorageInterface)) {
    throw new EntityStorageException(sprintf("The entity storage '%s' for the '%s' entity type does not support imports", get_class($entity_storage), $entity_type_id));
  }
  $entity_storage->importRename($names['old_name'], $new_config, $old_config);
  $this->setProcessedConfiguration($collection, 'rename', $rename_name);
  return TRUE;
}
doc_Drupal
2016-10-29 08:53:41
Comments
Leave a Comment

Please login to continue.