protected function EntityFile::getEntity in Drupal 10
Same name and namespace in other branches
- 8 core/modules/file/src/Plugin/migrate/destination/EntityFile.php \Drupal\file\Plugin\migrate\destination\EntityFile::getEntity()
- 9 core/modules/file/src/Plugin/migrate/destination/EntityFile.php \Drupal\file\Plugin\migrate\destination\EntityFile::getEntity()
Creates or loads an entity.
Parameters
\Drupal\migrate\Row $row: The row object.
array $old_destination_id_values: The old destination IDs.
Return value
\Drupal\Core\Entity\EntityInterface The entity we are importing into.
Overrides Entity::getEntity
File
- core/
modules/ file/ src/ Plugin/ migrate/ destination/ EntityFile.php, line 20
Class
- EntityFile
- Plugin annotation @MigrateDestination( id = "entity:file" )
Namespace
Drupal\file\Plugin\migrate\destinationCode
protected function getEntity(Row $row, array $old_destination_id_values) {
// For stub rows, there is no real file to deal with, let the stubbing
// process take its default path.
if ($row
->isStub()) {
return parent::getEntity($row, $old_destination_id_values);
}
// By default the entity key (fid) would be used, but we want to make sure
// we're loading the matching URI.
$destination = $row
->getDestinationProperty('uri');
if (empty($destination)) {
throw new MigrateException('Destination property uri not provided');
}
$entity = $this->storage
->loadByProperties([
'uri' => $destination,
]);
if ($entity) {
return reset($entity);
}
else {
return parent::getEntity($row, $old_destination_id_values);
}
}