class PrevNextHelper in Previous/Next API 8.2
Defines an PrevNextHelper service.
Hierarchy
- class \Drupal\prev_next\PrevNextHelper implements PrevNextHelperInterface
Expanded class hierarchy of PrevNextHelper
1 string reference to 'PrevNextHelper'
1 service uses PrevNextHelper
File
- src/
PrevNextHelper.php, line 11
Namespace
Drupal\prev_nextView source
class PrevNextHelper implements PrevNextHelperInterface {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* The config object.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs an PrevNextHelper object.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The Configuration Factory.
*/
public function __construct(Connection $database, ConfigFactoryInterface $config_factory) {
$this->database = $database;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
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;
}
/**
* {@inheritdoc}
*/
public function loadBundle($bundle_name) {
return $this->configFactory
->get('prev_next.node_type.' . $bundle_name);
}
/**
* {@inheritdoc}
*/
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;
}
}
/**
* {@inheritdoc}
*/
public function getPrevId($entity_id) {
return $this->database
->query("SELECT prev_nid FROM {prev_next_node} WHERE nid = :nid", array(
':nid' => $entity_id,
))
->fetchField();
}
/**
* {@inheritdoc}
*/
public function getNextId($entity_id) {
return $this->database
->query("SELECT next_nid FROM {prev_next_node} WHERE nid = :nid", array(
':nid' => $entity_id,
))
->fetchField();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PrevNextHelper:: |
protected | property | The config object. | |
PrevNextHelper:: |
protected | property | The database connection. | |
PrevNextHelper:: |
public | function |
Determine if connection should be refreshed. Overrides PrevNextHelperInterface:: |
|
PrevNextHelper:: |
public | function |
Callable API function to retun the next id of a given entity id. Overrides PrevNextHelperInterface:: |
|
PrevNextHelper:: |
public | function |
Callable API function to retun the prev id of a given entity id. Overrides PrevNextHelperInterface:: |
|
PrevNextHelper:: |
public | function |
Callable API function to get the next/prev id of a given entity id. Overrides PrevNextHelperInterface:: |
|
PrevNextHelper:: |
public | function |
Loads the Prev/next bundle configuration. Overrides PrevNextHelperInterface:: |
|
PrevNextHelper:: |
public | function | Constructs an PrevNextHelper object. |