-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrupal8API.theme
30 lines (27 loc) · 1.88 KB
/
Drupal8API.theme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
function Drupal8API_preprocess_node(&$variables) { // $variables is an array where are stored all Drupal's variables
$language = \Drupal::languageManager()->getCurrentLanguage()->getId(); // get the current language
$variables['lang_code'] = $language;
$variables['base_path'] = base_path(); // get the base path theme
$variables['is_front'] = Drupal::service('path.matcher')->isFrontPage(); // store the front page url using the path matcher service
$cuser = \Drupal::currentUser(); // get the current user;
if(!$cuser->id()) {
$variables['logged_in'] = "0"; // if false -> $variables['logged_in'] = "0"
} else {
$variables['logged_in'] = "1"; // if true -> $variables['logged_in] = "1"
}
}
function Drupal8API_preprocess_html(&$variables) {
$language = \Drupal::languageManager()->getCurrentLanguage()->getId(); // get the current language
$node = \Drupal::routeMatch()->getParameter('node'); // fetch the fields of the current node
if($node) { // if it exists
$variables['attributes']['class'][] = 'node-'.$node->id();// into $variables['attributes']['class'] I put the 'node-'.$node->id(); string
$currentNodeA = $node->toArray(); // cast into Array
$variables['attributes']['class'][] = 'node-type-'.$currentNodeA['type'][0]['target_id']; // into $variables['attributes']['class'] I put the 'node-type-'.$currentNodeA['type'][0]['target_id'] string
$variables['attributes']['class'][] = 'i18n-'.$language; // into $variables['attributes']['class'] I put the 'i18n-'.$language; string
if(isset($currentNodeA['field_structure'])) { // if is set the structure fields
$variables['attributes']['class'][] = 'tax-'.$currentNodeA['field_structure'][0]['target_id']; // into $variables['attributes']['class'] I put the 'tax-'.$currentNodeA['field_structure'][0]['target_id']; string
}
}
}
?>