You are here

protected function EntityRevision::getEntity in Workbench Moderation to Content Moderation 8.2

Gets the entity.

Parameters

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

array $old_destination_id_values: The old destination IDs.

Return value

\Drupal\Core\Entity\EntityInterface|false The entity or false if it can not be created.

Overrides EntityRevision::getEntity

File

src/Plugin/migrate/destination/EntityRevision.php, line 23

Class

EntityRevision
Fixes bugs in the core EntityRevision destination plugin:

Namespace

Drupal\wbm2cm\Plugin\migrate\destination

Code

protected function getEntity(Row $row, array $old_destination_id_values) {
  $revision_id = $old_destination_id_values ? reset($old_destination_id_values) : $row
    ->getDestinationProperty($this
    ->getKey('revision'));
  if (!empty($revision_id) && ($entity = $this->storage
    ->loadRevision($revision_id))) {
    $entity
      ->setNewRevision(FALSE);
  }
  else {
    $entity_id = $row
      ->getDestinationProperty($this
      ->getKey('id'));
    $entity = $this->storage
      ->load($entity_id);

    // If we fail to load the original entity something is wrong and we need
    // to return immediately.
    if (!$entity) {
      return FALSE;
    }
    $entity
      ->enforceIsNew(FALSE);
    $entity
      ->setNewRevision(TRUE);
  }
  return $this
    ->updateEntity($entity, $row) ?: $entity;
}