Last active
April 27, 2017 13:26
-
-
Save reinis-kinkeris/821ab1015c71d4a8574a55d6e90c225e to your computer and use it in GitHub Desktop.
Drupal 8 - switching views display based on taxonomy vocabulary id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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