Друпал 9

Шаблоны для разных режимов отображения терминов таксономии в Drupal 8/9

27 февраля 2021 - 22:31
/**
 * Implements hook_theme_suggestions_taxonomy_term_alter().
 */

function THEMENAME_theme_suggestions_taxonomy_term_alter(array &$suggestions, array $variables) {
  /** @var \Drupal\taxonomy\TermInterface $term */
  $term = $variables['elements']['#taxonomy_term'];
  $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
  // Add view mode theme suggestions.
  $suggestions[] = 'taxonomy_term__' . $sanitized_view_mode;
  $suggestions[] = 'taxonomy_term__' . $term->bundle() . '__' . $sanitized_view_mode;
  $suggestions[] = 'taxonomy_term__' . $term->id() . '__' . $sanitized_view_mode;
}

Подключение внешней JS-библиотеки в тему Drupal 8/9

18 февраля 2021 - 18:41
Код для файла THEMENAME.libraries.yml на примере Fancybox:
fancybox:
  remote: https://fancyapps.com/fancybox/3/
  version: 3.5.7
  license:
    name:  GNU GPLv3
    url: http://fancyapps.com/fancybox/3/#license
    gpl-compatible: true
  js:
    https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js: {type: external, minified: true}
  css:
    theme:
      https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css: {type: external, minified: true}