bibcite-8.x-1.x-dev/bibcite.module

bibcite.module
<?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);
  }
  $processed = $styler->render($data);
  $config = \Drupal::config('bibcite.settings');
  $convert_urls = $config->get('convert_urls') ?? FALSE;
  if ($convert_urls === TRUE) {
    $filter = new stdClass();
    $filter->settings = [
      'filter_url_length' => 72,
    ];
    $processed = _filter_url($processed, $filter);
  }
  $variables['content'] = [
    '#markup' => $processed,
  ];
}

/**
 * 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);
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc