You are here

public function EntityConfigBase::import in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php \Drupal\migrate\Plugin\migrate\destination\EntityConfigBase::import()
  2. 9 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: (optional) The old destination IDs. Defaults to an empty array.

Return value

array|bool An indexed array of destination IDs in the same order as defined in the plugin's getIds() method if the plugin wants to save the IDs to the ID map, TRUE to indicate success without saving IDs to the ID map, or FALSE to indicate a failure.

Throws

\Drupal\migrate\MigrateException Throws an exception if there is a problem importing the row. By default, this causes the migration system to treat this row as having failed; however, any \Drupal\migrate\Plugin\MigrateIdMapInterface status constant can be set using the $status parameter of \Drupal\migrate\MigrateException, such as \Drupal\migrate\Plugin\MigrateIdMapInterface::STATUS_IGNORED.

Overrides MigrateDestinationInterface::import

4 calls to EntityConfigBase::import()
EntityBlock::import in core/modules/block/src/Plugin/migrate/destination/EntityBlock.php
Import the row.
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.
EntitySearchPage::import in core/modules/search/src/Plugin/migrate/destination/EntitySearchPage.php
Import the row.
5 methods override EntityConfigBase::import()
EntityBlock::import in core/modules/block/src/Plugin/migrate/destination/EntityBlock.php
Import the row.
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.
EntitySearchPage::import in core/modules/search/src/Plugin/migrate/destination/EntitySearchPage.php
Import the row.

File

core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php, line 127

Class

EntityConfigBase
Base destination class for importing configuration entities.

Namespace

Drupal\migrate\Plugin\migrate\destination

Code

public function import(Row $row, array $old_destination_id_values = []) {
  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);

  // Translations are already saved in updateEntity by configuration override.
  if (!$this
    ->isTranslationDestination()) {
    $entity
      ->save();
  }
  if (count($ids) > 1) {

    // This can only be a config entity, content entities have their ID key
    // and that's it.
    $return = [];
    foreach ($id_keys as $id_key) {
      if ($this
        ->isTranslationDestination() && $id_key == 'langcode') {

        // Config entities do not have a language property, get the language
        // code from the destination.
        $return[] = $row
          ->getDestinationProperty($id_key);
      }
      else {
        $return[] = $entity
          ->get($id_key);
      }
    }
    return $return;
  }
  return [
    $entity
      ->id(),
  ];
}