You are here

public function CronJobListBuilder::buildRow in Ultimate Cron 8.2

Builds a row for an entity in the entity listing.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity for this row of the list.

Return value

array A render array structure of fields for this entity.

Overrides DraggableListBuilder::buildRow

See also

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

File

src/CronJobListBuilder.php, line 38

Class

CronJobListBuilder
Defines a class to build a listing of cron jobs.

Namespace

Drupal\ultimate_cron

Code

public function buildRow(EntityInterface $entity) {

  /* @var \Drupal\ultimate_cron\CronJobInterface $entity */
  $icon = drupal_get_path('module', 'ultimate_cron') . '/icons/hourglass.png';
  $behind_icon = [
    '#prefix' => ' ',
    '#theme' => 'image',
    '#uri' => file_create_url($icon),
    '#title' => t('Job is behind schedule!'),
  ];
  $log_entry = $entity
    ->loadLatestLogEntry();
  $row['label'] = $entity
    ->label();
  $row['module']['#markup'] = $entity
    ->getModuleName();
  $row['module']['#wrapper_attributes']['title'] = $entity
    ->getModuleDescription();
  $row['scheduled']['label']['#markup'] = $entity
    ->getPlugin('scheduler')
    ->formatLabel($entity);
  if ($entity
    ->isScheduled()) {
    $row['scheduled']['behind'] = $behind_icon;
  }

  // If the start time is 0, the jobs have never been run.
  $row['started']['#markup'] = $log_entry->start_time ? \Drupal::service('date.formatter')
    ->format($log_entry->start_time, "short") : $this
    ->t('Never');

  // Display duration
  $progress = $entity
    ->isLocked() ? $entity
    ->formatProgress() : '';
  $row['duration'] = [
    '#markup' => '<span class="duration-time" data-src="' . $log_entry
      ->getDuration() . '">' . $log_entry
      ->formatDuration() . '</span> <span class="duration-progress">' . $progress . '</span>',
    '#wrapper_attributes' => [
      'title' => $log_entry
        ->formatEndTime(),
    ],
  ];
  if (!$entity
    ->isValid()) {
    $row['status']['#markup'] = $this
      ->t('Missing');
  }
  elseif (!$entity
    ->status()) {
    $row['status']['#markup'] = $this
      ->t('Disabled');
  }
  else {

    // Get the status from the launcher when running, otherwise use the last
    // log entry.
    if ($entity
      ->isLocked() && $log_entry->lid == $entity
      ->isLocked()) {
      list($status, $title) = $entity
        ->getPlugin('launcher')
        ->formatRunning($entity);
    }
    elseif ($log_entry->start_time && !$log_entry->end_time) {
      list($status, $title) = $entity
        ->getPlugin('launcher')
        ->formatUnfinished($entity);
    }
    else {
      list($status, $title) = $log_entry
        ->formatSeverity();
      $title = $log_entry->message ? $log_entry->message : $title;
    }
    $row['status'] = $status;
    $row['status']['#wrapper_attributes']['title'] = $title;
  }
  $row += parent::buildRow($entity);
  $row['weight']['#delta'] = 50;
  return $row;
}