diff --git a/src/Plugin/Derivative/MigrateEntityReferenceRevisions.php b/src/Plugin/Derivative/MigrateEntityReferenceRevisions.php index 90390ec..2b8ae69 100644 --- a/src/Plugin/Derivative/MigrateEntityReferenceRevisions.php +++ b/src/Plugin/Derivative/MigrateEntityReferenceRevisions.php @@ -5,7 +5,12 @@ use Drupal\entity_reference_revisions\Plugin\migrate\destination\EntityReferenceRevisions; use Drupal\migrate\Plugin\Derivative\MigrateEntityRevision; +/** + * Class MigrateEntityReferenceRevisions + * @package Drupal\entity_reference_revisions\Plugin\Derivative + */ class MigrateEntityReferenceRevisions extends MigrateEntityRevision { + /** * {@inheritdoc} */ diff --git a/src/Plugin/migrate/destination/EntityReferenceRevisions.php b/src/Plugin/migrate/destination/EntityReferenceRevisions.php index 54388cc..5dd9ddd 100644 --- a/src/Plugin/migrate/destination/EntityReferenceRevisions.php +++ b/src/Plugin/migrate/destination/EntityReferenceRevisions.php @@ -3,6 +3,7 @@ namespace Drupal\entity_reference_revisions\Plugin\migrate\destination; use Drupal\Core\Entity\ContentEntityInterface; +use Drupal\migrate\MigrateException; use Drupal\migrate\Plugin\migrate\destination\EntityRevision; use Drupal\migrate\Row; @@ -71,13 +72,10 @@ public function getIds() { * {@inheritdoc} */ protected function getEntity(Row $row, array $oldDestinationIdValues) { - $entityId = $oldDestinationIdValues ? - reset($oldDestinationIdValues) : - $row->getDestinationProperty($this->getKey('id')); - $revisionId = $oldDestinationIdValues ? + $revision_id = $oldDestinationIdValues ? array_pop($oldDestinationIdValues) : $row->getDestinationProperty($this->getKey('revision')); - if (!empty($entityId) && !empty($revisionId) && ($entity = $this->loadEntityReferenceRevision($entityId, $revisionId))) { + if (!empty($revision_id) && ($entity = $this->storage->loadRevision($revision_id))) { $entity->setNewRevision(FALSE); } else { @@ -112,7 +110,7 @@ public function rollback(array $destination_identifiers) { * The IDs of the destination object to delete. */ protected function rollbackTranslation(array $destination_identifiers) { - $entity = $this->loadEntityReferenceRevision(reset($destination_identifiers), array_pop($destination_identifiers)); + $entity = $this->storage->loadRevision($destination_identifiers[1]); if ($entity && $entity instanceof TranslatableInterface) { if ($key = $this->getKey('langcode')) { if (isset($destination_identifier[$key])) { @@ -137,24 +135,9 @@ protected function rollbackTranslation(array $destination_identifiers) { * The IDs of the destination object to delete. */ protected function rollbackNonTranslation(array $destination_identifiers) { - $entity = $this->loadEntityReferenceRevision(reset($destination_identifiers), array_pop($destination_identifiers)); + $entity = $this->storage->loadRevision($destination_identifiers[1]); if ($entity) { $entity->delete(); } } - - /** - * Loads one entity reference revision entity. - * - * @param mixed $id - * The ID of the entity to load. - * - * @return \Drupal\Core\Entity\EntityInterface|null - * An entity object. NULL if no matching entity is found. - */ - public function loadEntityReferenceRevision($entityId, $revisionId) { - $entities = $this->storage->loadByProperties([$this->getKey('id') => $entityId, $this->getKey('revision') => $revisionId]); - return reset($entities) ?: NULL; - } - }