You are here

public function MigrateToolsCommands::fieldsSource in Migrate Tools 8.5

Same name and namespace in other branches
  1. 8.4 src/Commands/MigrateToolsCommands.php \Drupal\migrate_tools\Commands\MigrateToolsCommands::fieldsSource()

List the fields available for mapping in a source.

@command migrate:fields-source

@usage migrate:fields-source my_node List fields for the source in the my_node migration

@validate-module-enabled migrate_tools

@aliases mfs, migrate-fields-source

@field-labels machine_name: Machine Name description: Description @default-fields machine_name,description

Parameters

string $migration_id: ID of the migration.

Return value

\Consolidation\OutputFormatters\StructuredData\RowsOfFields Source fields of the given migration formatted as a table.

File

src/Commands/MigrateToolsCommands.php, line 752

Class

MigrateToolsCommands
Migrate Tools drush commands.

Namespace

Drupal\migrate_tools\Commands

Code

public function fieldsSource($migration_id) {

  /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
  $migration = $this->migrationPluginManager
    ->createInstance($migration_id);
  if ($migration) {
    $source = $migration
      ->getSourcePlugin();
    $table = [];
    foreach ($source
      ->fields() as $machine_name => $description) {
      $table[] = [
        'machine_name' => $machine_name,
        'description' => strip_tags($description),
      ];
    }
    return new RowsOfFields($table);
  }
  else {
    $error = dt('Migration @id does not exist', [
      '@id' => $migration_id,
    ]);
    $this
      ->logger()
      ->error($error);
    throw new \Exception($error);
  }
}