3 namespace Drupal\migrate\Plugin\migrate\destination;
5 use Drupal\migrate\Plugin\MigrationInterface;
6 use Drupal\migrate\Row;
9 * Defines the base abstract class for component entity display.
11 abstract class ComponentEntityDisplayBase extends DestinationBase {
18 public function import(Row $row, array $old_destination_id_values = []) {
20 // array_intersect_key() won't work because the order is important because
21 // this is also the return value.
22 foreach (array_keys($this->getIds()) as $id) {
23 $values[$id] = $row->getDestinationProperty($id);
25 $entity = $this->getEntity($values['entity_type'], $values['bundle'], $values[static::MODE_NAME]);
26 if (!$row->getDestinationProperty('hidden')) {
27 $entity->setComponent($values['field_name'], $row->getDestinationProperty('options') ?: []);
30 $entity->removeComponent($values['field_name']);
33 return array_values($values);
39 public function getIds() {
40 $ids['entity_type']['type'] = 'string';
41 $ids['bundle']['type'] = 'string';
42 $ids[static::MODE_NAME]['type'] = 'string';
43 $ids['field_name']['type'] = 'string';
50 public function fields(MigrationInterface $migration = NULL) {
51 // This is intentionally left empty.
57 * @param string $entity_type
58 * The entity type to retrieve.
59 * @param string $bundle
64 * @return \Drupal\Core\Entity\Display\EntityDisplayInterface
65 * The entity display object.
67 protected abstract function getEntity($entity_type, $bundle, $mode);