You are here

public function ComponentEntityDisplayBase::import in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/migrate/src/Plugin/migrate/destination/ComponentEntityDisplayBase.php \Drupal\migrate\Plugin\migrate\destination\ComponentEntityDisplayBase::import()

Import the row.

Derived classes must implement import(), to construct one new object (pre-populated) using ID mappings in the Migration.

Parameters

\Drupal\migrate\Row $row: The row object.

array $old_destination_id_values: The old destination ids.

Return value

mixed The entity id or an indication of success.

Overrides MigrateDestinationInterface::import

File

core/modules/migrate/src/Plugin/migrate/destination/ComponentEntityDisplayBase.php, line 20
Contains \Drupal\migrate\Plugin\migrate\destination\ComponentEntityDisplayBase.

Class

ComponentEntityDisplayBase

Namespace

Drupal\migrate\Plugin\migrate\destination

Code

public function import(Row $row, array $old_destination_id_values = array()) {
  $values = array();

  // array_intersect_key() won't work because the order is important because
  // this is also the return value.
  foreach (array_keys($this
    ->getIds()) as $id) {
    $values[$id] = $row
      ->getDestinationProperty($id);
  }
  $entity = $this
    ->getEntity($values['entity_type'], $values['bundle'], $values[static::MODE_NAME]);
  if (!$row
    ->getDestinationProperty('hidden')) {
    $entity
      ->setComponent($values['field_name'], $row
      ->getDestinationProperty('options') ?: array());
  }
  else {
    $entity
      ->removeComponent($values['field_name']);
  }
  $entity
    ->save();
  return array_values($values);
}