Skip to content

Instantly share code, notes, and snippets.

@reinis-kinkeris
Last active April 27, 2017 13:26
Show Gist options
  • Save reinis-kinkeris/821ab1015c71d4a8574a55d6e90c225e to your computer and use it in GitHub Desktop.
Save reinis-kinkeris/821ab1015c71d4a8574a55d6e90c225e to your computer and use it in GitHub Desktop.
Drupal 8 - switching views display based on taxonomy vocabulary id
name: Special terms
type: module
description: Provides views display switching for special terms
core: 8.x
version: 8.x-0.1.0
package: Taxonomy
dependencies:
- views
- taxonomy
<?php
use Drupal\views\ViewExecutable;
/**
* @implements hook_views_pre_view().
*
* @param \Drupal\views\ViewExecutable $view
* @param $display_id
* @param array $args
*/
function special_terms_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
if ($view->id() == 'taxonomy_term' && $display_id == 'page_1' && $term_id = $args[0]) {
$term = \Drupal\taxonomy\Entity\Term::load($term_id);
if (!is_null($term) && $term->get('vid')->target_id == 'vocabulary_id') {
$view->setDisplay('page_2');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment