public function PrevnextService::getPreviousNext in Prevnext 8
Same name and namespace in other branches
- 2.x src/PrevnextService.php \Drupal\prevnext\PrevnextService::getPreviousNext()
- 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 42
Class
- PrevnextService
- Class PrevnextService.
Namespace
Drupal\prevnextCode
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;
}