You are here

protected function DashboardController::buildQueuersQueueProcessors in Purge 8.3

Manage queuers, the queue itself and processors.

Return value

array The render array.

1 call to DashboardController::buildQueuersQueueProcessors()
DashboardController::build in modules/purge_ui/src/Controller/DashboardController.php
Build all dashboard sections.

File

modules/purge_ui/src/Controller/DashboardController.php, line 307

Class

DashboardController
Configuration dashboard for configuring the cache invalidation pipeline.

Namespace

Drupal\purge_ui\Controller

Code

protected function buildQueuersQueueProcessors() {
  extract($this
    ->getRenderLocals());

  // phpcs:disable DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable -- PHP's extract() isn't understood by this sniffer..
  $build = $details($this
    ->t('Queue'));
  $build['#description'] = $p($this
    ->t("The queue holds items that need refreshing, hold your mouse over the column titles for more details."));
  $build['#open'] = $this->request
    ->get('edit-queue', FALSE) || !count($this->purgeQueuers) || !count($this->purgeProcessors);
  $build['t'] = $table([
    'queuers' => [
      'data' => $this
        ->t('Queuers'),
      'title' => $this
        ->t('Queuers add items to the queue upon certain events, that processors process later on.'),
    ],
    'queue' => [
      'data' => $this
        ->t('Queue'),
      'title' => $this
        ->t("The queue holds 'invalidation items', which instruct what needs to be invalidated from external caches."),
    ],
    'processors' => [
      'data' => $this
        ->t('Processors'),
      'title' => $this
        ->t('Processors are responsible for emptying the queue and putting the purgers to work each time they process. Processors can work the queue constantly or at timed intervals, it is up to you to configure a policy that makes sense for the traffic nature of your website. Multiple processors will not lead to any parallel-processing or conflicts, instead it simply means the queue is checked more often.'),
    ],
  ]);

  // Build vertical columns for the queuers, queue and processors.
  $cols = [];
  $cols['queuers'] = [];
  foreach ($this->purgeQueuers as $queuer) {
    $definition = $queuer
      ->getPluginDefinition();
    $id = $queuer
      ->getPluginId();
    $ops = [];
    $ops['detail'] = $button($queuer
      ->getLabel(), [
      'queuer_detail',
      'id' => $id,
    ]);
    if (isset($definition['configform']) && !empty($definition['configform'])) {
      $ops['configure'] = $button($this
        ->t("Configure"), [
        'queuer_configd',
        'id' => $id,
      ]);
    }
    $ops['delete'] = $button($this
      ->t("Delete"), [
      'queuer_delete',
      'id' => $id,
    ]);
    $cols['queuers'][] = $cell_ops($ops);
  }
  $ops = [];
  $ops['detail'] = $button($this->purgeQueue
    ->getLabel(), 'queue_detail');
  $ops['browser'] = $button($this
    ->t('Inspect'), 'queue_browser', '900');
  $ops['change'] = $button($this
    ->t('Change engine'), 'queue_change', '900');
  $ops['empty'] = $button($this
    ->t('Empty'), 'queue_empty');
  $cols['queue'][] = $cell_ops($ops);
  $cols['processors'] = [];
  foreach ($this->purgeProcessors as $processor) {
    $definition = $processor
      ->getPluginDefinition();
    $id = $processor
      ->getPluginId();
    $ops = [];
    $ops['detail'] = $button($processor
      ->getLabel(), [
      'processor_detail',
      'id' => $id,
    ]);
    if (isset($definition['configform']) && !empty($definition['configform'])) {
      $ops['configure'] = $button($this
        ->t("Configure"), [
        'processor_configd',
        'id' => $id,
      ]);
    }
    $ops['delete'] = $button($this
      ->t("Delete"), [
      'processor_delete',
      'id' => $id,
    ]);
    $cols['processors'][] = $cell_ops($ops);
  }
  $col_equalize($cols);

  // Add one last row with 'Add ...' buttons.
  $col_equalize($cols, 1);
  if (count($this->purgeQueuers
    ->getPluginsAvailable())) {
    $cols['queuers'][] = $cell_ops([
      $button($this
        ->t("Add queuer"), 'queuer_add'),
    ]);
  }
  elseif (!count($this->purgeQueuers)) {
    $cols['queuers'][] = $cell_markup($b($this
      ->t("Please install a module to add at least one queuer.")));
  }
  if (count($this->purgeProcessors
    ->getPluginsAvailable())) {
    $cols['processors'][] = $cell_ops([
      $button($this
        ->t("Add processor"), 'processor_add'),
    ]);
  }
  elseif (!count($this->purgeProcessors)) {
    $cols['processors'][] = $cell_markup($b($this
      ->t("Please install a module to add at least one processor.")));
  }
  $col_equalize($cols);

  // Now transform the columns into table rows.
  foreach ($cols as $col => $rows) {
    foreach ($rows as $n => $row) {
      if (!$row_isset($build['t'], $n)) {
        $row_new($build['t'], $n, $cell());
      }
      $row_set($build['t'], $n, $col, $row);
    }
  }

  // phpcs:enable DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable
  return $build;
}