You are here

public function PrevnextService::getPreviousNext in Prevnext 2.x

Same name and namespace in other branches
  1. 8 src/PrevnextService.php \Drupal\prevnext\PrevnextService::getPreviousNext()
  2. 2.0.x src/PrevnextService.php \Drupal\prevnext\PrevnextService::getPreviousNext()

Retrieves previous and next nids of a given node, if they exist.

Parameters

\Drupal\node\Entity\Node $node: The node entity.

Return value

array An array of prev/next nids of given node.

Overrides PrevnextServiceInterface::getPreviousNext

File

src/PrevnextService.php, line 43

Class

PrevnextService
Class PrevnextService.

Namespace

Drupal\prevnext

Code

public function getPreviousNext(Node $node) {
  $nodes = $this
    ->getNodesOfType($node);
  $current_nid = $node
    ->id();
  $current_key = array_search($current_nid, $nodes);
  $this->prevnext['prev'] = $current_key == 0 ? '' : $nodes[$current_key - 1];
  $this->prevnext['next'] = $current_key == count($nodes) - 1 ? '' : $nodes[$current_key + 1];
  return $this->prevnext;
}