You are here

protected function ConfigImporter::importInvokeRename in Zircon Profile 8

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

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()

1 call to ConfigImporter::importInvokeRename()
ConfigImporter::importInvokeOwner in core/lib/Drupal/Core/Config/ConfigImporter.php
Invokes import* methods on configuration entity storage.

File

core/lib/Drupal/Core/Config/ConfigImporter.php, line 1002
Contains \Drupal\Core\Config\ConfigImporter.

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