how can I make a pager with the pager class? I could not find anywhere how to do this with the EntityQuery class. I have a pager(10)
that displays the last 10 items. I want to make a pager with numbers like
< 1, 2, 3, 4, 5, 6 >.
This is the code I have now:
class NewsArchive extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
// Query for newest articles and return max 3 results.
$query = \Drupal::entityQuery('node');
$news = $query->condition('type', 'news')
->condition('status', 1)
->sort('created', 'DESC')
->pager(10)
->execute();
// LoadMultiple News in $nodes variable
$nodes = Node::loadMultiple($news);
$path = base_path();
// Return $nodes variable with name items to the module.
return array(
'#theme' => 'mytheme_news_archive',
'#items' => $nodes,
'#path' => $path,
);
}
}
I have read somewhere that this was possible with the following code:
$build['pager'] = [
'#type' => 'pager',
];
How does this build pager (render) fit into my code? Can someone show me how to start?