function EntityFile::getEntity

Same name and namespace in other branches
  1. 9 core/modules/file/src/Plugin/migrate/destination/EntityFile.php \Drupal\file\Plugin\migrate\destination\EntityFile::getEntity()
  2. 8.9.x core/modules/file/src/Plugin/migrate/destination/EntityFile.php \Drupal\file\Plugin\migrate\destination\EntityFile::getEntity()
  3. 11.x 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
Provides migrate destination plugin for File entities.

Namespace

Drupal\file\Plugin\migrate\destination

Code

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.