EntityRevision.php in Workbench Moderation to Content Moderation 8.2
File
src/Plugin/migrate/destination/EntityRevision.php
View source
<?php
namespace Drupal\wbm2cm\Plugin\migrate\destination;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\destination\EntityRevision as BaseEntityRevision;
use Drupal\migrate\Row;
class EntityRevision extends BaseEntityRevision {
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 (!$entity) {
return FALSE;
}
$entity
->enforceIsNew(FALSE);
$entity
->setNewRevision(TRUE);
}
return $this
->updateEntity($entity, $row) ?: $entity;
}
public function getIds() {
$ids = parent::getIds();
if ($this
->isTranslationDestination()) {
if ($key = $this
->getKey('langcode')) {
$ids[$key] = $this
->getDefinitionFromEntity($key);
}
else {
throw new MigrateException('This entity type does not support translation.');
}
}
return $ids;
}
}