function AggregatorController::adminOverview

Same name in other branches
  1. 9 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\Core\Render\RendererInterface::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 108

Class

AggregatorController
Returns responses for aggregator module routes.

Namespace

Drupal\aggregator\Controller

Code

public function adminOverview() {
    $entity_type_manager = $this->entityTypeManager();
    $feeds = $entity_type_manager->getStorage('aggregator_feed')
        ->loadMultiple();
    $header = [
        $this->t('Title'),
        $this->t('Items'),
        $this->t('Last update'),
        $this->t('Next update'),
        $this->t('Operations'),
    ];
    $rows = [];
    
    /** @var \Drupal\aggregator\FeedInterface[] $feeds */
    foreach ($feeds as $feed) {
        $row = [];
        $row[] = $feed->toLink()
            ->toString();
        $row[] = $this->formatPlural($entity_type_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', [
            '@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 = $this->t('%time left', [
                '%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'] = [
            'title' => $this->t('Delete'),
            'url' => Url::fromRoute('entity.aggregator_feed.delete_form', [
                'aggregator_feed' => $feed->id(),
            ]),
        ];
        $links['delete_items'] = [
            'title' => $this->t('Delete items'),
            'url' => Url::fromRoute('aggregator.feed_items_delete', [
                'aggregator_feed' => $feed->id(),
            ]),
        ];
        $links['update'] = [
            'title' => $this->t('Update items'),
            'url' => Url::fromRoute('aggregator.feed_refresh', [
                'aggregator_feed' => $feed->id(),
            ]),
        ];
        $row[] = [
            'data' => [
                '#type' => 'operations',
                '#links' => $links,
            ],
        ];
        $rows[] = $row;
    }
    $build['feeds'] = [
        '#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>.', [
            ':link' => Url::fromRoute('aggregator.feed_add')->toString(),
        ]),
    ];
    return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.