You are here

prev_next.module in Previous/Next API 8.2

Same filename and directory in other branches
  1. 6 prev_next.module
  2. 7.2 prev_next.module
  3. 7 prev_next.module

Contains prev_next.module.

File

prev_next.module
View source
<?php

/**
 * @file
 * Contains prev_next.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\NodeInterface;

/**
 * Implements hook_help().
 */
function prev_next_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the prev_next module.
    case 'help.page.prev_next':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Provide a high performance API for previous/next nodes for a given node') . '</p>';
      return [
        '#markup' => $output,
      ];
  }
}

/**
 * Implements hook_theme().
 */
function prev_next_theme($existing, $type, $theme, $path) {
  $theme = [
    'prev_next_block' => [
      'variables' => [
        'prev_display' => NULL,
        'prev_text' => NULL,
        'prev_id' => NULL,
        'next_display' => NULL,
        'next_text' => NULL,
        'next_id' => NULL,
      ],
    ],
  ];
  return $theme;
}

/**
 * Implements hook_entity_insert().
 */
function prev_next_entity_insert(EntityInterface $entity) {
  $bundle_names = \Drupal::service('prev_next.helper')
    ->getBundleNames();
  if ($entity instanceof NodeInterface && in_array($entity
    ->getType(), $bundle_names)) {
    \Drupal::service('prev_next.api')
      ->add($entity
      ->id(), $entity
      ->getType());
  }
}

/**
 * Implements hook_entity_update().
 */
function prev_next_entity_update(EntityInterface $entity) {
  $bundle_names = \Drupal::service('prev_next.helper')
    ->getBundleNames();
  if ($entity instanceof NodeInterface && in_array($entity
    ->getType(), $bundle_names)) {
    \Drupal::service('prev_next.api')
      ->update($entity
      ->id(), $entity
      ->getType());
  }
}

/**
 * Implements hook_entity_delete().
 */
function prev_next_entity_delete(EntityInterface $entity) {
  $bundle_names = \Drupal::service('prev_next.helper')
    ->getBundleNames();
  if ($entity instanceof NodeInterface && in_array($entity
    ->getType(), $bundle_names)) {
    \Drupal::service('prev_next.api')
      ->remove($entity
      ->id(), $entity
      ->getType());
  }
}