3 namespace Drupal\migrate\Plugin\migrate\destination;
5 use Drupal\Core\Entity\ContentEntityInterface;
6 use Drupal\migrate\MigrateException;
7 use Drupal\migrate\Row;
10 * Provides entity revision destination plugin.
12 * @MigrateDestination(
13 * id = "entity_revision",
14 * deriver = "Drupal\migrate\Plugin\Derivative\MigrateEntityRevision"
17 class EntityRevision extends EntityContentBase {
22 protected static function getEntityTypeId($plugin_id) {
23 // Remove entity_revision:
24 return substr($plugin_id, 16);
30 * @param \Drupal\migrate\Row $row
32 * @param array $old_destination_id_values
33 * The old destination IDs.
35 * @return \Drupal\Core\Entity\EntityInterface|false
36 * The entity or false if it can not be created.
38 protected function getEntity(Row $row, array $old_destination_id_values) {
39 $revision_id = $old_destination_id_values ?
40 reset($old_destination_id_values) :
41 $row->getDestinationProperty($this->getKey('revision'));
42 if (!empty($revision_id) && ($entity = $this->storage->loadRevision($revision_id))) {
43 $entity->setNewRevision(FALSE);
46 $entity_id = $row->getDestinationProperty($this->getKey('id'));
47 $entity = $this->storage->load($entity_id);
49 // If we fail to load the original entity something is wrong and we need
50 // to return immediately.
55 $entity->enforceIsNew(FALSE);
56 $entity->setNewRevision(TRUE);
58 $this->updateEntity($entity, $row);
59 $entity->isDefaultRevision(FALSE);
66 protected function save(ContentEntityInterface $entity, array $old_destination_id_values = []) {
68 return [$entity->getRevisionId()];
74 public function getIds() {
75 if ($key = $this->getKey('revision')) {
76 return [$key => $this->getDefinitionFromEntity($key)];
78 throw new MigrateException('This entity type does not support revisions.');