3 namespace Drupal\migrate\Plugin\migrate\destination;
5 use Drupal\migrate\Plugin\MigrationInterface;
6 use Drupal\migrate\Row;
9 * Provides a destination plugin for migrating entity display components.
11 * Display modes provide different presentations for viewing ('view modes') or
12 * editing ('form modes') content. This destination plugin is an abstract base
13 * class for migrating fields and other components into view and form modes.
15 * @see \Drupal\migrate\Plugin\migrate\destination\PerComponentEntityDisplay
16 * @see \Drupal\migrate\Plugin\migrate\destination\PerComponentEntityFormDisplay
18 abstract class ComponentEntityDisplayBase extends DestinationBase {
25 public function import(Row $row, array $old_destination_id_values = []) {
27 // array_intersect_key() won't work because the order is important because
28 // this is also the return value.
29 foreach (array_keys($this->getIds()) as $id) {
30 $values[$id] = $row->getDestinationProperty($id);
32 $entity = $this->getEntity($values['entity_type'], $values['bundle'], $values[static::MODE_NAME]);
33 if (!$row->getDestinationProperty('hidden')) {
34 $entity->setComponent($values['field_name'], $row->getDestinationProperty('options') ?: []);
37 $entity->removeComponent($values['field_name']);
40 return array_values($values);
46 public function getIds() {
47 $ids['entity_type']['type'] = 'string';
48 $ids['bundle']['type'] = 'string';
49 $ids[static::MODE_NAME]['type'] = 'string';
50 $ids['field_name']['type'] = 'string';
57 public function fields(MigrationInterface $migration = NULL) {
58 // This is intentionally left empty.
64 * @param string $entity_type
65 * The entity type to retrieve.
66 * @param string $bundle
71 * @return \Drupal\Core\Entity\Display\EntityDisplayInterface
72 * The entity display object.
74 abstract protected function getEntity($entity_type, $bundle, $mode);