biopama_protected_areas-8.x-1.3/biopama_protected_areas.module
biopama_protected_areas.module
<?php use \Drupal\views\ViewExecutable; /* * implements hook_preprocess_node() */ function biopama_protected_areas_preprocess_node(&$variables) { $node = $variables['node']; /* * turn on dev_mode to see stuff that's in development through the templates. */ $variables['dev_mode'] = "false"; switch($node->getType()){ case 'protected_area': $variables['#attached']['library'][] = 'biopama_protected_areas/node-pa'; break; case 'country': $variables['#attached']['library'][] = 'biopama_protected_areas/node-country'; break; default: break; } } /* * implements hook_view_pre_render() */ function biopama_protected_areas_views_pre_render(\Drupal\views\ViewExecutable $view) { if (isset($view)){ switch($view->storage->id()){ case 'pa_search': $view->element['#attached']['library'][] = 'biopama_protected_areas/pa-search'; break; default: break; } } } /** * Implements hook_theme() to add the template definition. **/ function biopama_protected_areas_theme($existing, $type, $theme, $path) { return array( 'page__country' => array( 'base hook' => 'page', ), 'page__protected_area' => array( 'base hook' => 'page', ), 'page__pa_search' => array( 'base hook' => 'page', ), 'node__country' => array( 'base hook' => 'node', ), 'node__country__country_iso3_field' => array( 'base hook' => 'node', ), 'node__country__search_preview' => array( 'base hook' => 'node', ), 'node__country__teaser' => array( 'base hook' => 'node', ), 'node__protected_area' => array( 'base hook' => 'node', ), 'node__protected_area__search_preview' => array( 'base hook' => 'node', ), 'views_view_fields__breadcrumb_country_summary' => array( 'base hook' => 'views', ), 'views_view_fields__breadcrumb_protected_area_summary' => array( 'base hook' => 'views', ), 'views_view_fields__breadcrumb_region_summary' => array( 'base hook' => 'views', ), 'views_view__pa_search__pa_search' => array( 'base hook' => 'views', ), ); } function biopama_protected_areas_preprocess_node__country(array &$variables) { biopamaModuleCheck($variables); } function biopama_protected_areas_preprocess_node__protected_area(array &$variables) { biopamaModuleCheck($variables); } function biopamaModuleCheck(array &$variables) { $moduleHandler = \Drupal::service('module_handler'); $psrModuleCheck = "no"; $panoramaModuleCheck = "no"; if ($moduleHandler->moduleExists('biopama_psr')){ $psrModuleCheck = "yes"; } if ($moduleHandler->moduleExists('biopama_panorama')){ $panoramaModuleCheck = "yes"; } $variables['psr_module'] = $psrModuleCheck; $variables['panorama_module'] = $panoramaModuleCheck; } function biopama_protected_areas_preprocess_views_view_fields__breadcrumb_country_summary(array &$variables) { $variables['countryflags'] = '/' . drupal_get_path('module', 'biopama_protected_areas') . '/images/country_flags/'; } /** * Implements hook_theme_suggestions_taxonomy_term_alter(). */ function biopama_protected_areas_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; } function biopama_protected_areas_theme_suggestions_node_alter(array &$suggestions, array $variables, $hook) { $node = $variables['elements']['#node']; $type = $node->bundle(); $view_mode = $variables['elements']['#view_mode']; $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_'); $suggestions[] = 'node__'.$type; $suggestions[] = 'node__'.$type.'__'.$view_mode; } function biopama_protected_areas_theme_suggestions_page_alter(array &$suggestions, array $variables) { $node = NULL; $revision = NULL; if (\Drupal::routeMatch()->getParameter('node')) { //revision IDs are strings and node ids are strings when a revision is loaded. $node = \Drupal::routeMatch()->getParameter('node'); $revision = \Drupal::routeMatch()->getRawParameter('node_revision'); } $tid = NULL; $term = NULL; if (\Drupal::routeMatch()->getRawParameter('taxonomy_term')) { $tid = \Drupal::routeMatch()->getRawParameter('taxonomy_term'); $term = Term::load($tid); } //node parameters loaded by getParameter are objects and the bundle can be accessed normally. if (!empty($node)) { if ($revision) { $revised_node = \Drupal::entityTypeManager() ->getStorage('node') ->loadRevision($revision); $content_type = $revised_node->bundle(); } else { $content_type = $node->bundle(); } $suggestions[] = 'page__' . $content_type; } if (!empty($term)) { $vid = $term->vid->getValue(); $suggestions[] = 'page__taxonomy__vocabulary__' . $vid[0]['target_id']; } }