function EntityFile::getEntity
Same name in other branches
- 8.9.x core/modules/file/src/Plugin/migrate/destination/EntityFile.php \Drupal\file\Plugin\migrate\destination\EntityFile::getEntity()
- 10 core/modules/file/src/Plugin/migrate/destination/EntityFile.php \Drupal\file\Plugin\migrate\destination\EntityFile::getEntity()
- 11.x core/modules/file/src/Plugin/migrate/destination/EntityFile.php \Drupal\file\Plugin\migrate\destination\EntityFile::getEntity()
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);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.