QueueListBuilder.php in Advanced Queue 8
File
src/QueueListBuilder.php
View source
<?php
namespace Drupal\advancedqueue;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Url;
class QueueListBuilder extends ConfigEntityListBuilder {
public function buildHeader() {
$header['label'] = $this
->t('Queue');
$header['jobs'] = $this
->t('Jobs');
return $header + parent::buildHeader();
}
public function buildRow(EntityInterface $entity) {
$count_labels = [
Job::STATE_QUEUED => $this
->t('Queued'),
Job::STATE_PROCESSING => $this
->t('Processing'),
Job::STATE_SUCCESS => $this
->t('Success'),
Job::STATE_FAILURE => $this
->t('Failure'),
];
$jobs = [];
foreach ($entity
->getBackend()
->countJobs() as $state => $count) {
$jobs[] = sprintf('%s: %s', $count_labels[$state], $count);
}
$row['label'] = $entity
->label();
$row['jobs'] = implode(' | ', $jobs);
return $row + parent::buildRow($entity);
}
public function getDefaultOperations(EntityInterface $entity) {
$operations = parent::getDefaultOperations($entity);
if ($entity
->getBackendId() === 'database') {
$operations['jobs'] = [
'title' => $this
->t('List jobs'),
'weight' => -20,
'url' => Url::fromRoute('view.advancedqueue_jobs.page_1', [
'arg_0' => $entity
->id(),
]),
];
}
return $operations;
}
}