You are here

viewsreference.module in Views Reference Field 8

Same filename and directory in other branches
  1. 8.2 viewsreference.module

Module functions for viewsreference.

File

viewsreference.module
View source
<?php

/**
 * @file
 * Module functions for viewsreference.
 */
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\views\ViewExecutable;

/**
 * Implements hook_help().
 */
function viewsreference_help($route_name, RouteMatchInterface $arg) {
  switch ($route_name) {
    case 'help.page.viewsreference':
      $output = file_get_contents(drupal_get_path('module', 'viewsreference') . '/README.md');
      $output = \Drupal::moduleHandler()
        ->moduleExists('markdown') ? Xss::filterAdmin(\Drupal::moduleHandler()
        ->invoke('markdown', 'filter', [
        'process',
        0,
        -1,
        $output,
      ])) : '<h3>viewsreference README</h3><pre>' . Html::escape($output) . '</pre>';
      return $output;
  }
}

/**
 * Implements hook_theme().
 */
function viewsreference_theme($existing, $type, $theme, $path) {
  return [
    'viewsreference__view_title' => [
      'template' => 'viewsreference--view-title',
      'render element' => 'variables',
    ],
  ];
}

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function viewsreference_theme_suggestions_viewsreference__view_title(array $variables) {
  $suggestions = [];
  if (!empty($variables['variables']['#view']) && $variables['variables']['#view'] instanceof ViewExecutable) {
    $suggestions = $variables['variables']['#view']
      ->buildThemeFunctions('viewsreference__view_title');
  }
  return $suggestions;
}

/**
 * Implements hook_preprocess_viewsreference__view_title().
 */
function template_preprocess_viewsreference__view_title(&$variables) {
  $variables['title'] = [
    '#markup' => $variables['variables']['#title'],
  ];
  if (!empty($variables['variables']['#view'])) {
    \Drupal::service('renderer')
      ->addCacheableDependency($variables, $variables['variables']['#view']->storage);
  }
}

Functions