You are here

public function NextPreviousBlock::build in Next Previous Post Block (Node or Page Pagination) 8.5

Same name and namespace in other branches
  1. 8 src/Plugin/Block/NextPreviousBlock.php \Drupal\nextpre\Plugin\Block\NextPreviousBlock::build()
  2. 9.0.x src/Plugin/Block/NextPreviousBlock.php \Drupal\nextpre\Plugin\Block\NextPreviousBlock::build()
  3. 1.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\Block

Code

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($node);
    if (!empty($prev)) {
      $link['prev'] = $prev;
    }
    $next = $this
      ->generateNext($node);
    if (!empty($next)) {
      $link['next'] = $next;
    }
  }
  return $link;
}