You are here

public static function Migration::createEntityFromPlugin in Migrate Plus 8.4

Same name and namespace in other branches
  1. 8.5 src/Entity/Migration.php \Drupal\migrate_plus\Entity\Migration::createEntityFromPlugin()
  2. 8.2 src/Entity/Migration.php \Drupal\migrate_plus\Entity\Migration::createEntityFromPlugin()
  3. 8.3 src/Entity/Migration.php \Drupal\migrate_plus\Entity\Migration::createEntityFromPlugin()

Create a configuration entity from a core migration plugin's configuration.

Parameters

string $plugin_id: ID of a migration plugin managed by MigrationPluginManager.

string $new_plugin_id: ID to use for the new configuration entity.

Return value

\Drupal\migrate_plus\Entity\MigrationInterface A Migration configuration entity (not saved to persistent storage).

Note the list of properties being transplanted from the plugin instance or definition into the Migration config entity must remain in sync with the keys listed in the "config_export" annotation key of this class.

File

src/Entity/Migration.php, line 87

Class

Migration
Defines the Migration entity.

Namespace

Drupal\migrate_plus\Entity

Code

public static function createEntityFromPlugin($plugin_id, $new_plugin_id) {

  /** @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface $plugin_manager */
  $plugin_manager = \Drupal::service('plugin.manager.migration');
  $migration_plugin = $plugin_manager
    ->createInstance($plugin_id);
  $entity_array['id'] = $new_plugin_id;
  $plugin_definition = $migration_plugin
    ->getPluginDefinition();
  $migration_details['class'] = $plugin_definition['class'];
  if (isset($plugin_definition['field_plugin_method'])) {
    $migration_details['field_plugin_method'] = $plugin_definition['field_plugin_method'];
  }
  $entity_array['migration_tags'] = $migration_plugin
    ->get('migration_tags');
  $entity_array['label'] = $migration_plugin
    ->label();
  $entity_array['source'] = $migration_plugin
    ->getSourceConfiguration();
  $entity_array['destination'] = $migration_plugin
    ->getDestinationConfiguration();
  $entity_array['process'] = $migration_plugin
    ->getProcess();
  $entity_array['migration_dependencies'] = $migration_plugin
    ->getMigrationDependencies();
  $migration_entity = static::create($entity_array);
  return $migration_entity;
}