You are here

nivo_slider.module in Nivo Slider 8

Same filename and directory in other branches
  1. 6 nivo_slider.module
  2. 7 nivo_slider.module

Primarily Drupal hooks.

File

nivo_slider.module
View source
<?php

/**
 * @file
 * Primarily Drupal hooks.
 */
use Drupal\Core\Routing\RouteMatchInterface;

// Include the slider functions.
include_once 'includes/nivo_slider_slider.inc';

/**
 * Implements hook_help().
 */
function nivo_slider_help($route_name, RouteMatchInterface $arg) {
  switch ($route_name) {
    case 'help.page.nivo_slider':
      $output = '';
      $output .= '<p>' . t('<a href="@project_page">Nivo Slider</a> provides an easy and eye-catching way to showcase featured content.', [
        '@project_page' => 'http://drupal.org/project/nivo_slider',
      ]) . '</p>';
      $output .= '<h2>' . t('Usage') . '</h2>';
      $output .= '<p>' . t('Nivo Slider provides a block which will determine where the slider is placed. Administrators or users with the Administer Nivo Slider permission will be able to configure slider settings by visiting the <a href="nivo_slider">Nivo Slider</a> administration page.', [
        '@nivo_slider' => url('admin/structure/nivo-slider'),
      ]) . '</p>';
      $output .= '<h2>' . t('Configuration') . '</h2>';
      $output .= '<p>' . t('Nivo Slider provides two configuration pages: slides and options.') . '</p>';
      $output .= '<h3>' . t('Slides') . '</h3>';
      $output .= '<p>' . t('The <a href="@slides">slides</a> page provides an interface for managing the content of the slider. Slider content can be given a title or description, made into a link, reordered or restricted to displaying on a specific path.', [
        '@slides' => url('admin/structure/nivo-slider'),
      ]) . '</p>';
      $output .= '<h3>' . t('Options') . '</h3>';
      $output .= '<p>' . t('The <a href="@options">options</a> page provides an interface for configuring the slider. Slider options include general options, transitions and navigation.', [
        '@options' => url('admin/structure/nivo-slider/options'),
      ]) . '</p>';
      return $output;
    case 'admin/structure/nivo-slider':
      $output = '';
      $output .= '<p>' . t('Configure slider content.') . '</p>';
      return $output;
    case 'admin/structure/nivo-slider/slides':
      $output = '';
      $output .= '<p>' . t('Configure slider content.') . '</p>';
      return $output;
    case 'admin/structure/nivo-slider/options':
      $output = '';
      $output .= '<p>' . t('Configure slider options.') . '</p>';
      return $output;
  }
}

/**
 * Implements hook_i18n_string_info()
 */
function nivo_slider_i18n_string_info() {
  $groups['nivo_slider'] = [
    'title' => t('Nivo Slider'),
    'description' => t('Slide titles and descriptions.'),
    'format' => TRUE,
    'list' => FALSE,
    'refresh callback' => 'nivo_slider_locale_refresh',
  ];
  return $groups;
}

/**
 * Update / create translation source for user defined slide strings.
 *
 * @param array $slides
 *   An array of slider slides.
 */
function nivo_slider_locale_refresh(array $slides = NULL) {
  if (!isset($slides)) {
    $slides = variable_get('nivo_slider_banner_settings', []);
  }
  foreach ($slides as $slide => $settings) {
    foreach ($settings as $setting => $value) {
      switch ($setting) {
        case 'title':
          i18n_string_update('nivo_slider:slide:' . $slide . ':title', $value);
          break;
        case 'description':
          i18n_string_update('nivo_slider:slide:' . $slide . ':description', $value['value'], [
            'format' => $value['format'],
          ]);
          break;
      }
    }
  }
}

/**
 * Translates a user defined slide string.
 *
 * @param string $name
 *   Location glued with ':'.
 * @param string $string
 *   String in default language. Default language may or may not be English.
 * @param int $langcode
 *   The language code if it is different from the page request one.
 * @param string $textgroup
 *   Textgroup.
 *
 * @return string
 *   Translated string, $string if not found.
 */
function nivo_slider_translate($name, $string, $langcode = NULL, $textgroup = 'nivo_slider') {
  return function_exists('i18n_string') ? i18n_string($textgroup . ':' . $name, $string, [
    'langcode' => $langcode,
  ]) : $string;
}

/**
 * Implements hook_theme().
 */
function nivo_slider_theme($existing, $type, $theme, $path) {
  return [
    'nivo_slider_wrapper' => [
      'variables' => [
        'themes' => NULL,
        'banners' => NULL,
        'html_captions' => NULL,
      ],
      'template' => 'nivo-slider-wrapper',
      'file' => 'templates/theme.inc',
    ],
  ];
}

/**
 * Implements hook_hook_info().
 */
function nivo_slider_hook_info() {
  $hooks['nivo_slider_theme_info'] = [
    'group' => 'nivo_slider',
  ];
  $hooks['nivo_slider_theme_info_alter'] = [
    'group' => 'nivo_slider',
  ];
  return $hooks;
}

Functions

Namesort descending Description
nivo_slider_help Implements hook_help().
nivo_slider_hook_info Implements hook_hook_info().
nivo_slider_i18n_string_info Implements hook_i18n_string_info()
nivo_slider_locale_refresh Update / create translation source for user defined slide strings.
nivo_slider_theme Implements hook_theme().
nivo_slider_translate Translates a user defined slide string.