You are here

protected function StatisticsPopularBlock::nodeTitleList in Drupal 9

Same name and namespace in other branches
  1. 8 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
Builds and returns the renderable array for this block plugin.

File

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

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(),
    ],
  ];
}