PrevNextHelper.php in Previous/Next API 8.2
File
src/PrevNextHelper.php
View source
<?php
namespace Drupal\prev_next;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Driver\mysql\Connection;
class PrevNextHelper implements PrevNextHelperInterface {
protected $database;
protected $configFactory;
public function __construct(Connection $database, ConfigFactoryInterface $config_factory) {
$this->database = $database;
$this->configFactory = $config_factory;
}
public function getBundleNames() {
$bundle_names = [];
foreach ($this->configFactory
->listAll('prev_next.node_type.') as $config) {
$contents = explode('.', $config);
$bundle_names[] = end($contents);
}
return $bundle_names;
}
public function loadBundle($bundle_name) {
return $this->configFactory
->get('prev_next.node_type.' . $bundle_name);
}
public function getPrevnextId($entity_id, $op = 'next') {
switch ($op) {
case 'prev':
return $this
->getPrevId($entity_id);
case 'next':
return $this
->getNextId($entity_id);
default:
return 0;
}
}
public function getPrevId($entity_id) {
return $this->database
->query("SELECT prev_nid FROM {prev_next_node} WHERE nid = :nid", array(
':nid' => $entity_id,
))
->fetchField();
}
public function getNextId($entity_id) {
return $this->database
->query("SELECT next_nid FROM {prev_next_node} WHERE nid = :nid", array(
':nid' => $entity_id,
))
->fetchField();
}
}