You are here

public function FieldGroup::import in Field Group 8

Same name and namespace in other branches
  1. 8.3 contrib/field_group_migrate/src/Plugin/migrate/destination/d7/FieldGroup.php \Drupal\field_group_migrate\Plugin\migrate\destination\d7\FieldGroup::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: (optional) The old destination IDs. Defaults to an empty array.

Return value

array|bool An indexed array of destination IDs in the same order as defined in the plugin's getIds() method if the plugin wants to save the IDs to the ID map, TRUE to indicate success without saving IDs to the ID map, or FALSE to indicate a failure.

Overrides MigrateDestinationInterface::import

File

contrib/field_group_migrate/src/Plugin/migrate/destination/d7/FieldGroup.php, line 26
Contains \Drupal\field_group_migrate\Plugin\migrate\destination\d7\FieldGroup.

Class

FieldGroup
This class imports one field_group of an entity form display.

Namespace

Drupal\field_group_migrate\Plugin\migrate\destination\d7

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['mode'], $values['type']);
  if (!$entity
    ->isNew()) {
    $settings = $row
      ->getDestinationProperty('settings');
    $entity
      ->setThirdPartySetting('field_group', $row
      ->getDestinationProperty('group_name'), $settings);
    if (isset($settings['format_type']) && $settings['format_type'] == 'hidden') {
      $entity
        ->unsetThirdPartySetting('field_group', $row
        ->getDestinationProperty('group_name'));
    }
    $entity
      ->save();
  }
  return array_values($values);
}