You are here

public function EntityConfigBase::import in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase::import()

Import the row.

Derived classes must implement import(), to construct one new object (pre-populated) using ID mappings in the Migration.

Parameters

\Drupal\migrate\Row $row: The row object.

array $old_destination_id_values: The old destination ids.

Return value

mixed The entity id or an indication of success.

Overrides MigrateDestinationInterface::import

2 calls to EntityConfigBase::import()
EntityCommentType::import in core/modules/comment/src/Plugin/migrate/destination/EntityCommentType.php
Import the row.
EntityNodeType::import in core/modules/node/src/Plugin/migrate/destination/EntityNodeType.php
Import the row.
3 methods override EntityConfigBase::import()
EntityCommentType::import in core/modules/comment/src/Plugin/migrate/destination/EntityCommentType.php
Import the row.
EntityImageStyle::import in core/modules/image/src/Plugin/migrate/destination/EntityImageStyle.php
Import the row.
EntityNodeType::import in core/modules/node/src/Plugin/migrate/destination/EntityNodeType.php
Import the row.

File

core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php, line 31
Contains \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase.

Class

EntityConfigBase
Class for importing configuration entities.

Namespace

Drupal\migrate\Plugin\migrate\destination

Code

public function import(Row $row, array $old_destination_id_values = array()) {
  if ($row
    ->isStub()) {
    throw new MigrateException('Config entities can not be stubbed.');
  }
  $this->rollbackAction = MigrateIdMapInterface::ROLLBACK_DELETE;
  $ids = $this
    ->getIds();
  $id_key = $this
    ->getKey('id');
  if (count($ids) > 1) {

    // Ids is keyed by the key name so grab the keys.
    $id_keys = array_keys($ids);
    if (!$row
      ->getDestinationProperty($id_key)) {

      // Set the id into the destination in for form "val1.val2.val3".
      $row
        ->setDestinationProperty($id_key, $this
        ->generateId($row, $id_keys));
    }
  }
  $entity = $this
    ->getEntity($row, $old_destination_id_values);
  $entity
    ->save();
  if (count($ids) > 1) {

    // This can only be a config entity, content entities have their id key
    // and that's it.
    $return = array();
    foreach ($id_keys as $id_key) {
      $return[] = $entity
        ->get($id_key);
    }
    return $return;
  }
  return array(
    $entity
      ->id(),
  );
}