function StatisticsPopularBlock::nodeTitleList

Same name and namespace in other branches
  1. 9 core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php \Drupal\statistics\Plugin\Block\StatisticsPopularBlock::nodeTitleList()
  2. 10 core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php \Drupal\statistics\Plugin\Block\StatisticsPopularBlock::nodeTitleList()
  3. 11.x core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php \Drupal\statistics\Plugin\Block\StatisticsPopularBlock::nodeTitleList()

Generates the ordered array of node links for build().

Parameters

int[] $nids: An ordered array of node ids.

string $title: The title for the list.

Return value

array A render array for the list.

1 call to StatisticsPopularBlock::nodeTitleList()
StatisticsPopularBlock::build in core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php

File

core/modules/statistics/src/Plugin/Block/StatisticsPopularBlock.php, line 191

Class

StatisticsPopularBlock
Provides a 'Popular content' block.

Namespace

Drupal\statistics\Plugin\Block

Code

protected function nodeTitleList(array $nids, $title) {
    $nodes = $this->entityTypeManager
        ->getStorage('node')
        ->loadMultiple($nids);
    $items = [];
    foreach ($nids as $nid) {
        $node = $this->entityRepository
            ->getTranslationFromContext($nodes[$nid]);
        $item = $node->toLink()
            ->toRenderable();
        $this->renderer
            ->addCacheableDependency($item, $node);
        $items[] = $item;
    }
    return [
        '#theme' => 'item_list__node',
        '#items' => $items,
        '#title' => $title,
        '#cache' => [
            'tags' => $this->entityTypeManager
                ->getDefinition('node')
                ->getListCacheTags(),
        ],
    ];
}

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