You are here

bibcite.module in Bibliography & Citation 8

Same filename and directory in other branches
  1. 2.0.x bibcite.module

Main module hooks.

File

bibcite.module
View source
<?php

/**
 * @file
 * Main module hooks.
 */
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;

/**
 * Implements hook_theme().
 */
function bibcite_theme($existing, $type, $theme, $path) {
  return [
    'bibcite_citation' => [
      'variables' => [
        'data' => [],
        'style' => NULL,
      ],
    ],
  ];
}

/**
 * Implements hook_preprocess_HOOK().
 */
function bibcite_preprocess_bibcite_citation(&$variables) {

  /** @var \Drupal\bibcite\CitationStylerInterface $styler */
  $styler = \Drupal::service('bibcite.citation_styler');
  $data = $variables['data'];
  if ($variables['style']) {
    $styler
      ->setStyleById($variables['style']);
  }
  else {
    $styler
      ->setStyle(NULL);
  }
  $variables['content'] = [
    '#markup' => $styler
      ->render($data),
  ];
}

/**
 * Implements hook_help().
 */
function bibcite_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.bibcite':
      $links = [
        ':proc' => Url::fromRoute('bibcite.settings')
          ->toString(),
        ':csl' => Url::fromRoute('entity.bibcite_csl_style.collection')
          ->toString(),
      ];
      $module = 'bibcite';
      return \Drupal::service('bibcite.help_service')
        ->getHelpMarkup($links, $route_name, $module);
  }
}

Functions