public function NextPreviousBlock::build in Next Previous Post Block (Node or Page Pagination) 1.0.x
Same name and namespace in other branches
- 8.5 src/Plugin/Block/NextPreviousBlock.php \Drupal\nextpre\Plugin\Block\NextPreviousBlock::build()
- 8 src/Plugin/Block/NextPreviousBlock.php \Drupal\nextpre\Plugin\Block\NextPreviousBlock::build()
- 9.0.x src/Plugin/Block/NextPreviousBlock.php \Drupal\nextpre\Plugin\Block\NextPreviousBlock::build()
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides BlockPluginInterface::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ NextPreviousBlock.php, line 132
Class
- NextPreviousBlock
- Provides a 'Next Previous' block.
Namespace
Drupal\nextpre\Plugin\BlockCode
public function build() {
$link = [];
// Get the created time of the current node.
$node = $this->routeMatch
->getParameter('node');
if ($node instanceof NodeInterface && $node
->getType() == $this->configuration['content_type']) {
$current_nid = $node
->id();
$prev = $this
->generatePrevious($current_nid);
if (!empty($prev)) {
$link['prev'] = $prev;
}
$next = $this
->generateNext($current_nid);
if (!empty($next)) {
$link['next'] = $next;
}
}
return $link;
}