function twigsuggest_theme_suggestions_taxonomy_term in Twig Template Suggester 8
Implements hook_theme_suggestions_HOOK() for taxonomy terms.
Currently Drupal core's taxonomy term module only provides:
- $suggestions[] = 'taxonomy_term__' . $term->bundle();
- $suggestions[] = 'taxonomy_term__' . $term->id() . $term->bundle();
This is a very basic template suggestion that should be in core: https://www.drupal.org/project/drupal/issues/2767243
File
- ./
twigsuggest.module, line 313 - Twig Template Suggester module hook implementations.
Code
function twigsuggest_theme_suggestions_taxonomy_term(array $variables) {
$term = $variables['elements']['#taxonomy_term'];
// We allow dots in view modes?! But keeping this from discarded core patch.
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
$suggestions[] = 'taxonomy_term__' . $term
->bundle() . '__' . $sanitized_view_mode;
$suggestions[] = 'taxonomy_term__' . $sanitized_view_mode;
$suggestions[] = 'taxonomy_term__' . $term
->id() . '__' . $term
->bundle() . '__' . $sanitized_view_mode;
$suggestions[] = 'taxonomy_term__' . $term
->id() . '__' . $sanitized_view_mode;
return $suggestions;
}