You are here

public function MessageController::overview in Migrate Tools 8

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

Displays a listing of migration messages.

Messages are truncated at 56 chars.

Return value

array A render array as expected by drupal_render().

1 string reference to 'MessageController::overview'
migrate_tools.routing.yml in ./migrate_tools.routing.yml
migrate_tools.routing.yml

File

src/Controller/MessageController.php, line 71
Contains \Drupal\migrate_tools\Controller\MessageController.

Class

MessageController
Returns responses for migrate_tools message routes.

Namespace

Drupal\migrate_tools\Controller

Code

public function overview($migration_group, $migration) {
  $rows = [];
  $classes = static::getLogLevelClassMap();

  /** @var MigrationInterface $migration */
  $migration = Migration::load($migration);
  $source_id_field_names = array_keys($migration
    ->getSourcePlugin()
    ->getIds());
  $column_number = 1;
  foreach ($source_id_field_names as $source_id_field_name) {
    $header[] = [
      'data' => $source_id_field_name,
      'field' => 'sourceid' . $column_number++,
      'class' => [
        RESPONSIVE_PRIORITY_MEDIUM,
      ],
    ];
  }
  $header[] = [
    'data' => $this
      ->t('Severity level'),
    'field' => 'level',
    'class' => [
      RESPONSIVE_PRIORITY_LOW,
    ],
  ];
  $header[] = [
    'data' => $this
      ->t('Message'),
    'field' => 'message',
  ];
  $message_table = $migration
    ->getIdMap()
    ->messageTableName();
  $query = $this->database
    ->select($message_table, 'm')
    ->extend('\\Drupal\\Core\\Database\\Query\\PagerSelectExtender')
    ->extend('\\Drupal\\Core\\Database\\Query\\TableSortExtender');
  $query
    ->fields('m');
  $result = $query
    ->limit(50)
    ->orderByHeader($header)
    ->execute();
  foreach ($result as $message_row) {
    $column_number = 1;
    foreach ($source_id_field_names as $source_id_field_name) {
      $column_name = 'sourceid' . $column_number++;
      $row[$column_name] = $message_row->{$column_name};
    }
    $row['level'] = $message_row->level;
    $row['message'] = $message_row->message;
    $row['class'] = [
      Html::getClass('migrate-message-' . $message_row->level),
      $classes[$message_row->level],
    ];
    $rows[] = $row;
  }
  $build['message_table'] = [
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#attributes' => [
      'id' => $message_table,
      'class' => [
        $message_table,
      ],
    ],
    '#empty' => $this
      ->t('No messages for this migration.'),
  ];
  $build['message_pager'] = [
    '#type' => 'pager',
  ];
  return $build;
}