You are here

public function MigrationHelper::alterRow in Inline Entity Form 8

Adds all bundles for the entity type to the row.

Drupal 7 inline_entity_form set the target bundles to an empty array to indicate all bundles are referenced. In Drupal 8+ all the target bundles are listed in the handler settings. Therefore, when the target bundle is an empty array get all the bundles and put them on the row.

Parameters

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

\Drupal\migrate\Plugin\MigrateSourceInterface $source: The source for this migration.

\Drupal\migrate\Plugin\MigrationInterface $migration: The migration.

Throws

\Exception

File

src/MigrationHelper.php, line 76

Class

MigrationHelper
Helper for migration hooks in inline_entity_form.module.

Namespace

Drupal\inline_entity_form

Code

public function alterRow(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) {
  if ($source) {
    if (get_class($source) === FieldInstance::class && $row
      ->get('type') === 'entityreference') {
      $widget = $row
        ->get('widget/type');
      if ($widget === 'inline_entity_form_single' || $widget === 'inline_entity_form') {
        $data = $row
          ->get('field_definition/data');
        $definition = unserialize($data);
        if (empty($definition['settings']['handler_settings']['target_bundles'])) {
          $entity_type = $row
            ->get('entity_type');
          $bundles = $this
            ->getBundles($source, $entity_type);
        }
      }
    }
    $bundles = $bundles ?? [];
    $row
      ->setSourceProperty('target_bundles', $bundles);
  }
}