You are here

public function MigrationListBuilder::buildRow in Migrate Tools 8.5

Same name and namespace in other branches
  1. 8 src/Controller/MigrationListBuilder.php \Drupal\migrate_tools\Controller\MigrationListBuilder::buildRow()
  2. 8.2 src/Controller/MigrationListBuilder.php \Drupal\migrate_tools\Controller\MigrationListBuilder::buildRow()
  3. 8.3 src/Controller/MigrationListBuilder.php \Drupal\migrate_tools\Controller\MigrationListBuilder::buildRow()
  4. 8.4 src/Controller/MigrationListBuilder.php \Drupal\migrate_tools\Controller\MigrationListBuilder::buildRow()

Builds a row for a migration plugin.

Parameters

\Drupal\Core\Entity\EntityInterface $migration_entity: The migration plugin for which to build the row.

Return value

array|null A render array of the table row for displaying the plugin information.

Overrides EntityListBuilder::buildRow

See also

\Drupal\Core\Entity\EntityListController::render()

File

src/Controller/MigrationListBuilder.php, line 140

Class

MigrationListBuilder
Provides a listing of migration entities in a given group.

Namespace

Drupal\migrate_tools\Controller

Code

public function buildRow(EntityInterface $migration_entity) {
  try {

    /** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
    $migration = $this->migrationPluginManager
      ->createInstance($migration_entity
      ->id());
    $migration_group = $migration_entity
      ->get('migration_group');
    if (!$migration_group) {
      $migration_group = 'default';
    }
    $route_parameters = [
      'migration_group' => $migration_group,
      'migration' => $migration
        ->id(),
    ];
    $row['label'] = [
      'data' => [
        '#type' => 'link',
        '#title' => $migration
          ->label(),
        '#url' => Url::fromRoute("entity.migration.overview", $route_parameters),
      ],
    ];
    $row['machine_name'] = $migration
      ->id();
    $row['status'] = $migration
      ->getStatusLabel();
  } catch (\Exception $e) {
    $this->logger
      ->warning('Migration entity id %id is malformed: %orig', [
      '%id' => $migration_entity
        ->id(),
      '%orig' => $e
        ->getMessage(),
    ]);
    return NULL;
  }
  try {

    // Derive the stats.
    $source_plugin = $migration
      ->getSourcePlugin();
    $row['total'] = $source_plugin
      ->count();
    $map = $migration
      ->getIdMap();
    $row['imported'] = $map
      ->importedCount();

    // -1 indicates uncountable sources.
    if ($row['total'] == -1) {
      $row['total'] = $this
        ->t('N/A');
      $row['unprocessed'] = $this
        ->t('N/A');
    }
    else {
      $row['unprocessed'] = $row['total'] - $map
        ->processedCount();
    }
    $row['messages'] = [
      'data' => [
        '#type' => 'link',
        '#title' => $map
          ->messageCount(),
        '#url' => Url::fromRoute("migrate_tools.messages", $route_parameters),
      ],
    ];
    $migrate_last_imported_store = \Drupal::keyValue('migrate_last_imported');
    $last_imported = $migrate_last_imported_store
      ->get($migration
      ->id(), FALSE);
    if ($last_imported) {

      /** @var \Drupal\Core\Datetime\DateFormatter $date_formatter */
      $date_formatter = \Drupal::service('date.formatter');
      $row['last_imported'] = $date_formatter
        ->format($last_imported / 1000, 'custom', 'Y-m-d H:i:s');
    }
    else {
      $row['last_imported'] = '';
    }
    $row['operations']['data'] = [
      '#type' => 'dropbutton',
      '#links' => [
        'simple_form' => [
          'title' => $this
            ->t('Execute'),
          'url' => Url::fromRoute('migrate_tools.execute', [
            'migration_group' => $migration_group,
            'migration' => $migration
              ->id(),
          ]),
        ],
      ],
    ];
  } catch (\Throwable $throwable) {
    $this
      ->handleThrowable($row);
  }
  return $row;
}