EntityRevision.php in Zircon Profile 8
File
core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php
View source
<?php
namespace Drupal\migrate\Plugin\migrate\destination;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Row;
class EntityRevision extends EntityContentBase {
protected static function getEntityTypeId($plugin_id) {
return substr($plugin_id, 16);
}
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);
}
$this
->updateEntity($entity, $row);
$entity
->isDefaultRevision(FALSE);
return $entity;
}
protected function save(ContentEntityInterface $entity, array $old_destination_id_values = array()) {
$entity
->save();
return array(
$entity
->getRevisionId(),
);
}
public function getIds() {
if ($key = $this
->getKey('revision')) {
$ids[$key]['type'] = 'integer';
return $ids;
}
throw new MigrateException('This entity type does not support revisions.');
}
}
Classes
Name |
Description |
EntityRevision |
Plugin annotation
@MigrateDestination(
id = "entity_revision",
deriver = "Drupal\migrate\Plugin\Derivative\MigrateEntityRevision"
) |