public function ScheduleListBuilder::buildRow in Backup and Migrate 8.4
Same name and namespace in other branches
- 5.0.x src/Controller/ScheduleListBuilder.php \Drupal\backup_migrate\Controller\ScheduleListBuilder::buildRow()
ScheduleListBuilder save implementation requires instance of Schedule. Signature enforced by EntityListBuilder.
@throw InvalidArgumentException
Overrides EntityListBuilder::buildRow
File
- src/
Controller/ ScheduleListBuilder.php, line 36
Class
- ScheduleListBuilder
- Provides a listing of Schedule entities.
Namespace
Drupal\backup_migrate\ControllerCode
public function buildRow(EntityInterface $entity) {
if (!$entity instanceof Schedule) {
throw new Exception();
}
$row['label'] = $entity
->label();
$row['enabled'] = $entity
->get('enabled') ? $this
->t('Yes') : $this
->t('No');
$row['period'] = $entity
->getPeriodFormatted();
$row['last_run'] = $this
->t('Never');
$time = \Drupal::time();
if ($last_run = $entity
->getLastRun()) {
$row['last_run'] = \Drupal::service('date.formatter')
->format($last_run, 'small');
$row['last_run'] .= ' (' . $this
->t('@time ago', [
'@time' => \Drupal::service('date.formatter')
->formatInterval($time
->getRequestTime() - $last_run),
]) . ')';
}
$row['next_run'] = $this
->t('Not Scheduled');
if (!$entity
->get('enabled')) {
$row['next_run'] = $this
->t('Disabled');
}
elseif ($next_run = $entity
->getNextRun()) {
$interval = \Drupal::service('date.formatter')
->formatInterval(abs($next_run - $time
->getRequestTime()));
if ($next_run > $time
->getRequestTime()) {
$row['next_run'] = \Drupal::service('date.formatter')
->format($next_run, 'small');
$row['next_run'] .= ' (' . $this
->t('in @time', [
'@time' => $interval,
]) . ')';
}
else {
$row['next_run'] = $this
->t('Next cron run');
if ($last_run) {
$row['next_run'] .= ' (' . $this
->t('was due @time ago', [
'@time' => $interval,
]) . ')';
}
}
}
$row['keep'] = \Drupal::translation()
->formatPlural($entity
->get('keep'), 'Last 1 backup', 'Last @count backups');
return $row + parent::buildRow($entity);
}