function EntityRevision::getEntity
Same name in this branch
- 11.x core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php \Drupal\Tests\migrate\Unit\destination\EntityRevision::getEntity()
Same name in other branches
- 9 core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php \Drupal\migrate\Plugin\migrate\destination\EntityRevision::getEntity()
- 9 core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php \Drupal\Tests\migrate\Unit\destination\EntityRevision::getEntity()
- 8.9.x core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php \Drupal\migrate\Plugin\migrate\destination\EntityRevision::getEntity()
- 8.9.x core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php \Drupal\Tests\migrate\Unit\destination\EntityRevision::getEntity()
- 10 core/modules/migrate/src/Plugin/migrate/destination/EntityRevision.php \Drupal\migrate\Plugin\migrate\destination\EntityRevision::getEntity()
- 10 core/modules/migrate/tests/src/Unit/destination/EntityRevisionTest.php \Drupal\Tests\migrate\Unit\destination\EntityRevision::getEntity()
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 Entity::getEntity
1 call to EntityRevision::getEntity()
- EntityRevision::getEntity in core/
modules/ migrate/ tests/ src/ Unit/ destination/ EntityRevisionTest.php - Allow public access for testing.
2 methods override EntityRevision::getEntity()
- EntityRevision::getEntity in core/
modules/ migrate/ tests/ src/ Unit/ destination/ EntityRevisionTest.php - Allow public access for testing.
- EntityRevisionTestDestination::getEntity in core/
modules/ migrate/ tests/ src/ Unit/ Plugin/ migrate/ destination/ EntityRevisionTest.php - Gets the entity.
File
-
core/
modules/ migrate/ src/ Plugin/ migrate/ destination/ EntityRevision.php, line 137
Class
- EntityRevision
- Provides entity revision destination plugin.
Namespace
Drupal\migrate\Plugin\migrate\destinationCode
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'));
$entity = NULL;
if (!empty($revision_id)) {
/** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */
$storage = $this->storage;
if ($entity = $storage->loadRevision($revision_id)) {
$entity->setNewRevision(FALSE);
}
}
if ($entity === NULL) {
$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);
}
// We need to update the entity, so that the destination row IDs are
// correct.
$entity = $this->updateEntity($entity, $row);
$entity->isDefaultRevision(FALSE);
return $entity;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.