You are here

public function AggregatorController::adminOverview in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/aggregator/src/Controller/AggregatorController.php \Drupal\aggregator\Controller\AggregatorController::adminOverview()

Displays the aggregator administration page.

Return value

array A render array as expected by drupal_render().

1 string reference to 'AggregatorController::adminOverview'
aggregator.routing.yml in core/modules/aggregator/aggregator.routing.yml
core/modules/aggregator/aggregator.routing.yml

File

core/modules/aggregator/src/Controller/AggregatorController.php, line 114
Contains \Drupal\aggregator\Controller\AggregatorController.

Class

AggregatorController
Returns responses for aggregator module routes.

Namespace

Drupal\aggregator\Controller

Code

public function adminOverview() {
  $entity_manager = $this
    ->entityManager();
  $feeds = $entity_manager
    ->getStorage('aggregator_feed')
    ->loadMultiple();
  $header = array(
    $this
      ->t('Title'),
    $this
      ->t('Items'),
    $this
      ->t('Last update'),
    $this
      ->t('Next update'),
    $this
      ->t('Operations'),
  );
  $rows = array();

  /** @var \Drupal\aggregator\FeedInterface[] $feeds */
  foreach ($feeds as $feed) {
    $row = array();
    $row[] = $feed
      ->link();
    $row[] = $this
      ->formatPlural($entity_manager
      ->getStorage('aggregator_item')
      ->getItemCount($feed), '1 item', '@count items');
    $last_checked = $feed
      ->getLastCheckedTime();
    $refresh_rate = $feed
      ->getRefreshRate();
    $row[] = $last_checked ? $this
      ->t('@time ago', array(
      '@time' => $this->dateFormatter
        ->formatInterval(REQUEST_TIME - $last_checked),
    )) : $this
      ->t('never');
    if (!$last_checked && $refresh_rate) {
      $next_update = $this
        ->t('imminently');
    }
    elseif ($last_checked && $refresh_rate) {
      $next_update = $next = $this
        ->t('%time left', array(
        '%time' => $this->dateFormatter
          ->formatInterval($last_checked + $refresh_rate - REQUEST_TIME),
      ));
    }
    else {
      $next_update = $this
        ->t('never');
    }
    $row[] = $next_update;
    $links['edit'] = [
      'title' => $this
        ->t('Edit'),
      'url' => Url::fromRoute('entity.aggregator_feed.edit_form', [
        'aggregator_feed' => $feed
          ->id(),
      ]),
    ];
    $links['delete'] = array(
      'title' => $this
        ->t('Delete'),
      'url' => Url::fromRoute('entity.aggregator_feed.delete_form', [
        'aggregator_feed' => $feed
          ->id(),
      ]),
    );
    $links['delete_items'] = array(
      'title' => $this
        ->t('Delete items'),
      'url' => Url::fromRoute('aggregator.feed_items_delete', [
        'aggregator_feed' => $feed
          ->id(),
      ]),
    );
    $links['update'] = array(
      'title' => $this
        ->t('Update items'),
      'url' => Url::fromRoute('aggregator.feed_refresh', [
        'aggregator_feed' => $feed
          ->id(),
      ]),
    );
    $row[] = array(
      'data' => array(
        '#type' => 'operations',
        '#links' => $links,
      ),
    );
    $rows[] = $row;
  }
  $build['feeds'] = array(
    '#prefix' => '<h3>' . $this
      ->t('Feed overview') . '</h3>',
    '#type' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => $this
      ->t('No feeds available. <a href=":link">Add feed</a>.', array(
      ':link' => $this
        ->url('aggregator.feed_add'),
    )),
  );
  return $build;
}