You are here

public function MigrationHelper::alterPlugins in Inline Entity Form 8

Alters the field migrations for the inline_entity_form widget.

Parameters

array $migrations: An array of migrations.

Throws

\Drupal\Component\Plugin\Exception\PluginException

File

src/MigrationHelper.php, line 26

Class

MigrationHelper
Helper for migration hooks in inline_entity_form.module.

Namespace

Drupal\inline_entity_form

Code

public function alterPlugins(array &$migrations) {
  foreach ($migrations as &$migration) {

    /** @var \Drupal\migrate\Plugin\MigratePluginManager $migration_plugin_manager */
    $migration_plugin_manager = \Drupal::service('plugin.manager.migration');
    $migration_stub = $migration_plugin_manager
      ->createStubMigration($migration);

    /** @var \Drupal\migrate\Plugin\MigrateSourcePluginManager $source_plugin_manager */
    $source_plugin_manager = \Drupal::service('plugin.manager.migrate.source');
    $source = NULL;
    $configuration = $migration['source'];
    $source = $source_plugin_manager
      ->createInstance($migration['source']['plugin'], $configuration, $migration_stub);
    if ($source) {

      // Field instance.
      if (get_class($source) === FieldInstance::class) {
        $settings[] = $migration['process']['settings'];
        $addition = [
          'inline_entity_form' => [
            'plugin' => 'inline_entity_form_field_instance_settings',
          ],
        ];
        $settings = NestedArray::mergeDeepArray([
          $settings,
          $addition,
        ], TRUE);
        $migration['process']['settings'] = $settings;
      }
      if (is_a($source, FieldInstancePerFormDisplay::class)) {
        $addition = [
          'inline_entity_form_single' => 'inline_entity_form_simple',
          'inline_entity_form' => 'inline_entity_form_complex',
        ];
        $migration['process']['options/type']['type']['map'] = array_merge($migration['process']['options/type']['type']['map'], $addition);
      }
    }
  }
}