You are here

protected function Entity::getEntity in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Plugin/migrate/destination/Entity.php \Drupal\migrate\Plugin\migrate\destination\Entity::getEntity()
  2. 9 core/modules/migrate/src/Plugin/migrate/destination/Entity.php \Drupal\migrate\Plugin\migrate\destination\Entity::getEntity()

Creates or loads an entity.

Parameters

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

array $old_destination_id_values: The old destination IDs.

Return value

\Drupal\Core\Entity\EntityInterface The entity we are importing into.

5 calls to Entity::getEntity()
EntityConfigBase::import in core/modules/migrate/src/Plugin/migrate/destination/EntityConfigBase.php
Import the row.
EntityContentBase::import in core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php
EntityFile::getEntity in core/modules/file/src/Plugin/migrate/destination/EntityFile.php
Creates or loads an entity.
EntityImageStyle::import in core/modules/image/src/Plugin/migrate/destination/EntityImageStyle.php
Import the row.
EntityShortcutSet::getEntity in core/modules/shortcut/src/Plugin/migrate/destination/EntityShortcutSet.php
Creates or loads an entity.
5 methods override Entity::getEntity()
EntityContentComplete::getEntity in core/modules/migrate/src/Plugin/migrate/destination/EntityContentComplete.php
Gets the entity.
EntityFile::getEntity in core/modules/file/src/Plugin/migrate/destination/EntityFile.php
Creates or loads an entity.
EntityRevision::getEntity in core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php
Gets the entity.
EntityShortcutSet::getEntity in core/modules/shortcut/src/Plugin/migrate/destination/EntityShortcutSet.php
Creates or loads an entity.
EntityTestDestination::getEntity in core/modules/migrate/tests/src/Unit/Plugin/migrate/destination/EntityContentBaseTest.php
Creates or loads an entity.

File

core/modules/migrate/src/Plugin/migrate/destination/Entity.php, line 155

Class

Entity
Provides a generic destination to import entities.

Namespace

Drupal\migrate\Plugin\migrate\destination

Code

protected function getEntity(Row $row, array $old_destination_id_values) {
  $entity_id = reset($old_destination_id_values) ?: $this
    ->getEntityId($row);
  if (!empty($entity_id) && ($entity = $this->storage
    ->load($entity_id))) {

    // Allow updateEntity() to change the entity.
    $entity = $this
      ->updateEntity($entity, $row) ?: $entity;
  }
  else {

    // Attempt to ensure we always have a bundle.
    if ($bundle = $this
      ->getBundle($row)) {
      $row
        ->setDestinationProperty($this
        ->getKey('bundle'), $bundle);
    }

    // Stubs might need some required fields filled in.
    if ($row
      ->isStub()) {
      $this
        ->processStubRow($row);
    }
    $entity = $this->storage
      ->create($row
      ->getDestination());
    $entity
      ->enforceIsNew();
  }
  return $entity;
}