views_rss_yandex-2.0.0/views_rss_yandex.module

views_rss_yandex.module
<?php

/**
 * @file
 * Provides Yandex namespace and <item> elements for Views RSS module.
 */

use Drupal\Component\Utility\Html;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function views_rss_yandex_help($route_name, RouteMatchInterface $route_match) {
  if ($route_name === 'help.page.views_rss_yandex') {
    $text = file_get_contents(__DIR__ . '/README.md');
    return '<pre>' . Html::escape($text) . '</pre>';
  }
  return '';
}

/**
 * Implements hook_views_rss_namespaces().
 */
function views_rss_yandex_views_rss_namespaces() {
  $namespaces['yandex'] = [
    'prefix' => 'xmlns',
    'uri' => 'http://news.yandex.ru',
  ];
  $namespaces['media'] = [
    'prefix' => 'xmlns',
    'uri' => 'http://search.yahoo.com/mrss/',
  ];
  return $namespaces;
}

/**
 * Implements hook_views_rss_item_elements().
 */
function views_rss_yandex_views_rss_item_elements() {
  $elements['yandex:full-text'] = [
    'description' => t('Full message text for search index.'),
    'help' => 'http://partner.news.yandex.ru/tech.pdf',
  ];
  $elements['yandex:genre'] = [
    'description' => t('Should be either lenta, message, article or interview.'),
    'help' => 'http://partner.news.yandex.ru/tech.pdf',
  ];
  $elements['yandex:enclosure'] = [
    'description' => t('Handles several enclosure elements per item.'),
    'help' => 'http://partner.news.yandex.ru/tech.pdf',
  ];

  return $elements;
}

/**
 * Implements hook_theme_registry_alter().
 */
function views_rss_yandex_theme_registry_alter(array &$registry) {
  // Use the twig file that comes with this module so that the CDATA wrapper can
  // be added.
  $module_dir = \Drupal::service('extension.list.module')->getPath('views_rss_yandex');
  $registry['views_view_row_rss']['path'] = $module_dir . '/templates';
}

/**
 * Implements template_preprocess_views_view_row_rss().
 */
function views_rss_yandex_preprocess_views_view_row_rss(&$variables) {
  if (
    isset($variables['view']->style_plugin->options['feed_settings']['yandex_turbo'])
    && $variables['view']->style_plugin->options['feed_settings']['yandex_turbo'] === 1
  ) {
    $variables['yandex_turbo_enabled'] = TRUE;
  }
}

/**
 * Implements template_preprocess_views_view_rss().
 */
function views_rss_yandex_preprocess_views_view_rss(&$variables) {
  if (
    isset($variables['view']->style_plugin->options['feed_settings']['yandex_turbo'])
    && $variables['view']->style_plugin->options['feed_settings']['yandex_turbo'] === 1
  ) {
    /** @var \Drupal\Core\Template\Attribute $namespaces */
    $namespaces = $variables['namespaces'];
    $namespaces->setAttribute('xmlns:turbo', 'http://turbo.yandex.ru');
  }
}

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

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