You are here

entity_pager.module in Entity Pager 8

Same filename and directory in other branches
  1. 7 entity_pager.module
  2. 2.0.x entity_pager.module

Provides Next and Previous navigation on entities.

File

entity_pager.module
View source
<?php

/**
 * @file
 * Provides Next and Previous navigation on entities.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function entity_pager_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.entity_pager':
      $output = '';
      $output .= t('<h3>About</h3>');
      $output .= t('<p>Provides next and previous navigation on entities.<p>');
      $output .= t('<p> &nbsp e.g.<p>');
      $output .= t('<p> &nbsp < prev &nbsp All &nbsp next ><p>');
      $output .= t('<p>You can add multiple different navigation blocks on the same entity. This module combines Views, Blocks, Tokens and has its own internal intelligent advice system giving tips that are published to Watchdog (optionally). It is designed to run fast with the minimum of processing.</p>');
      $output .= t('<p>It is simple to use, allowing you can create Navigation blocks in a few seconds. For more complex pagers, it can combine with the Entity Reference module to create generic sub-navigation on related entities.</p>');
      $output .= t('<p> &nbsp e.g. navigate through a Brands products or go back to the Brand page itself.</p>');
      $output .= t('<p> &nbsp < prev &nbsp Pepsi &nbsp next ></p>');
      $output .= t('<p><strong>Demonstration Block/View:</strong></p>');
      $output .= t('<p>When turning on this module an Entity Pager demonstration View block is created called: <strong>Entity Pager Example</strong>.  Enable this block in a region of your theme on a page with a node on and this will display an Entity Pager block for nodes.</p>');
      $output .= t('<p>See demonstration video at:  <a href="https://youtu.be/oJUcjKLz8ls" title="Entity Pager module on YouTube" rel="nofollow">Entity Pager module on YouTube</a>');
      return $output;
  }
}

/**
 * Prepares variables for entity pager templates.
 *
 * Default template: entity-pager.html.twig.
 *
 * @param array $variables
 *   An associative array containing:
 *   - view: The view of the entity pager.
 */
function template_preprocess_entity_pager(array &$variables) {
  $options = $variables['view']->style_plugin->options;

  /** @var \Drupal\entity_pager\EntityPagerFactory $factory */
  $factory = \Drupal::service('entity_pager.factory');
  $entityPager = $factory
    ->get($variables['view'], $options);
  $variables['links'] = $entityPager
    ->getLinks();
  $variables['count_word'] = $entityPager
    ->getCountWord();
  $variables['#attached']['library'][] = 'entity_pager/entity-pager';
  $variables['#cache']['contexts'][] = 'url.path';
}

Functions

Namesort descending Description
entity_pager_help Implements hook_help().
template_preprocess_entity_pager Prepares variables for entity pager templates.