talkingmaps-8.x-1.9/talkingmaps.module
talkingmaps.module
<?php
/**
* implementing hook_theme().
*/
use \Drupal\taxonomy\Entity\Term;
function talkingmaps_theme($existing, $type, $theme, $path) {
return [
'node__talkingmaps' => [
'base hook' => 'node',
],
'views_view__talkingmaps' => [
'base hook' => 'views',
],
'page__talkingmaps' => [
'base hook' => 'page',
],
];
}
function talkingmaps_preprocess(&$variables, $hook) {
$variables['base_url'] = $GLOBALS['base_url']; /*\Drupal::request()->getRequestUri();*/
}
function talkingmaps_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'];
}
}
