You are here

public function EntityFieldCollection::import in Field collection 8

Same name and namespace in other branches
  1. 8.3 src/Plugin/migrate/destination/EntityFieldCollection.php \Drupal\field_collection\Plugin\migrate\destination\EntityFieldCollection::import()

Throws

\Drupal\migrate\MigrateException When an entity cannot be looked up.

\Drupal\migrate\Exception\EntityValidationException When an entity validation hasn't been passed.

Overrides EntityContentBase::import

File

src/Plugin/migrate/destination/EntityFieldCollection.php, line 18

Class

EntityFieldCollection
Plugin annotation @MigrateDestination( id = "entity:field_collection_item" )

Namespace

Drupal\field_collection\Plugin\migrate\destination

Code

public function import(Row $row, array $old_destination_id_values = []) {

  /** @var \Drupal\field_collection\Entity\FieldCollectionItem $field_collection */
  $field_collection = $this
    ->getEntity($row, $old_destination_id_values);
  if ($field_collection
    ->isNew()) {

    // Set host entity based on values passed from source.
    $host_entity = \Drupal::entityTypeManager()
      ->getStorage($row
      ->getDestinationProperty('host_type'))
      ->load($row
      ->getDestinationProperty('host_entity_id'));
    $field_collection
      ->setHostEntity($host_entity);
  }
  $field_collection
    ->save();
  return [
    $field_collection
      ->id(),
  ];
}