You are here

alpha_pagination.module in Views Alpha Pagination 8.2

Same filename and directory in other branches
  1. 7.2 alpha_pagination.module
  2. 7 alpha_pagination.module

Module hooks and alters for the Views Alpha Pagination module.

File

alpha_pagination.module
View source
<?php

/**
 * @file
 * Module hooks and alters for the Views Alpha Pagination module.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Component\Utility\Html;

/**
 * Implements hook_help().
 *
 * @todo Remove inline styling.
 */
function alpha_pagination_help($route_name, RouteMatchInterface $route_match) {
  $output = NULL;
  switch ($route_name) {
    case 'help.page.alpha_pagination':
      $output .= '<h4>' . t('Overview') . '</h4>';
      $output .= t('The Alpha Pagination for Views module enables you to add an alphabetical menu in the header or footer of a views display.');
      $output .= '<div style="border-top: 2px solid #f8981d; margin: 15px 0px; width: 100%"></div>';
      $output .= '<b>' . t('Views Integration and Configuration') . '</b>';
      $output .= '<ol>';
      $output .= '<li>' . t('Build a new view of either users, content (nodes), or comments.') . '</li>';
      $output .= '<li>' . t("Add whatever field you want to use as the basis for the alphabetic grouping (e.g. title, body). You can optionally exclude this field from display if you don't want it to appear in the results shown on the page for some reason. You can only choose a field that is a textfield, textarea or a textarea with a summary.") . '</li>';
      $output .= '<li>' . t('Add either a header or a footer to your view. Select the new item available in the menu of options for Global: Alpha Pagination.') . '</li>';
      $output .= '<li>' . t('Configure how you want alpha_pagination to work and specify where it should appear:');
      $output .= '<ol style="list-style-type: lower-alpha;">';
      $output .= '<li>' . t('set the path to the results view page.') . '</li>';
      $output .= '<li>' . t('select the field you want to use as the basis for the alphabetic grouping from the options presented in the select list (note: if the field you want to use does not appear, go back and add it to your view and then return to this configuration page to select the field).') . '</li>';
      $output .= '<li>' . t('add a context that is the same as the field you wish to use as the basis for alphabetic sorting. Be sure to enable Glossary mode and set the character limit to 1. The transform case option on the URL should be set to Upper Case.') . '</li>';
      $output .= '<li>' . t('by default the alpha pagination will apply to all displays; if you only want the alpha pagination to appear on the current display, use the drop-down menu at the top of the administrative interface to change the setting from "All displays" to "This page (override)".') . '</li>';
      $output .= '</ol>';
      $output .= '<li>' . t("An optional sample view is included and can be enabled via the alpha_pagination_example view. The sample relies on the \\'article\\' default content type. You can create sample content using the devel module or rely on your own data.") . '</li>';
      $output .= '</ol>';
      $output .= '<div style="border-top: 2px solid #f8981d; margin: 15px 0px; width: 100%"></div>';
      $output .= '<h4>' . t('Additional Style Optional') . '</h4>';
      $output .= t('In addition, you can specify the CSS style classes around the paginator, the item list and each item whether or not it is active or inactive. This includes the ability to set a class for linked items (as opposed to items to which have no options and therefor no links).') . '<br /><br />';
      $output .= t('Furthermore, you can add an "ALL" item as well as numeric items and specify their positions in navigation, the label and their respective css class as well.');
      $output .= '<div style="border-top: 2px solid #f8981d; margin: 15px 0px; padding-top: 15px; width: 100%; font-size: 8pt; line-height: 1.3em;">';
      break;
    default:
      break;
  }
  return $output;
}

/**
 * Implements hook_node_presave().
 */
function alpha_pagination_entity_presave(EntityInterface $entity) {
  if ($entity instanceof ContentEntityInterface) {
    Cache::invalidateTags([
      'alpha_pagination:' . $entity
        ->getEntityTypeId(),
    ]);
  }
}

/**
 * Implements hook_token_info().
 *
 * @see \views_handler_area_alpha_pagination::getTokens()
 */
function alpha_pagination_token_info() {
  $info['types']['alpha_pagination'] = [
    'name' => t('Views Alpha Pagination'),
    'description' => t('Tokens related to the current alpha pagination display on the view.'),
    'needs-data' => 'alpha_pagination',
  ];
  $info['tokens']['alpha_pagination']['path'] = [
    'name' => t('Path'),
    'description' => t('The current path of the view (if page display) or current_path().'),
  ];
  $info['tokens']['alpha_pagination']['value'] = [
    'name' => t('Value'),
    'description' => t('The current character value.'),
  ];
  return $info;
}

/**
 * Implements hook_tokens().
 *
 * {@inheritdoc}
 *
 * @see \views_handler_area_alpha_pagination::getTokens()
 */
function alpha_pagination_tokens($type, $tokens, array $data = [], array $options = []) {
  $sanitize = !empty($options['sanitize']);
  $replacements = [];
  if ($type === 'alpha_pagination' && !empty($data['alpha_pagination']) && ($alpha_pagination = $data['alpha_pagination'])) {
    foreach ($tokens as $name => $original) {
      if (isset($alpha_pagination[$name])) {
        $replacements[$original] = $sanitize ? Html::escape($alpha_pagination[$name]) : $alpha_pagination[$name];
      }
    }
  }
  return $replacements;
}

Functions

Namesort descending Description
alpha_pagination_entity_presave Implements hook_node_presave().
alpha_pagination_help Implements hook_help().
alpha_pagination_tokens Implements hook_tokens().
alpha_pagination_token_info Implements hook_token_info().