FieldGroupEntityViewDisplay.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Drupal\field_group_migrate\Plugin\migrate\destination;
  3. use Drupal\migrate\Plugin\migrate\destination\PerComponentEntityDisplay;
  4. use Drupal\migrate\Row;
  5. /**
  6. * This class imports one field_group of an entity form display.
  7. *
  8. * @MigrateDestination(
  9. * id = "field_group_entity_view_display"
  10. * )
  11. */
  12. class FieldGroupEntityViewDisplay extends PerComponentEntityDisplay {
  13. /**
  14. * {@inheritdoc}
  15. */
  16. public function import(Row $row, array $old_destination_id_values = array()) {
  17. $values = array();
  18. // array_intersect_key() won't work because the order is important because
  19. // this is also the return value.
  20. foreach (array_keys($this->getIds()) as $id) {
  21. $values[$id] = $row->getDestinationProperty($id);
  22. }
  23. foreach ($row->getSourceProperty('view_modes') as $view_mode => $settings) {
  24. $entity = $this->getEntity($values['entity_type'], $values['bundle'], $view_mode);
  25. if (!$entity->isNew()) {
  26. $settings = array_merge($row->getDestinationProperty('field_group'), $settings);
  27. $entity->setThirdPartySetting('field_group', $row->getDestinationProperty('id'), $settings);
  28. if (isset($settings['format_type']) && ($settings['format_type'] == 'no_style' || $settings['format_type'] == 'hidden')) {
  29. $entity->unsetThirdPartySetting('field_group', $row->getDestinationProperty('id'));
  30. }
  31. $entity->save();
  32. }
  33. }
  34. return array_values($values);
  35. }
  36. }