This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmilaniztheme.theme
executable file
·50 lines (41 loc) · 1.66 KB
/
milaniztheme.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @file
* Theme functions
*/
// Include all files from the includes directory.
$includes_path = dirname(__FILE__) . '/includes/*.inc';
foreach (glob($includes_path) as $filename) {
require_once dirname(__FILE__) . '/includes/' . basename($filename);
}
function milaniztheme_theme_suggestions_page_alter(array &$suggestions, array $variables) {
// Add content type suggestions.
if ($node = \Drupal::request()->attributes->get('node')) {
array_splice($suggestions, 1, 0, 'page__node__' . $node->getType());
}
}
function milaniztheme_preprocess_html (&$variables) {
if ($node = \Drupal::request()->attributes->get('node')) {
$variables['attributes']['class'][] = 'node-type-' . $node->getType();
}
if ($node = \Drupal::request()->attributes->get('node')) {
$variables['attributes']['class'][] = 'page-node-' . $node->id();
}
// The getRoles() method will return us the machine names, so there is no
// need to process roles names additionally. However, I suggest prefixing
// the names with "role-", so it's more obvious.
foreach ($variables['user']->getRoles() as $role) {
$variables['attributes']['class'][] = 'role-' . $role;
}
}
function milaniztheme_preprocess_page (&$variables) {
if (!array_key_exists('node', $variables))
return;
$node = $variables['node'];
$variables['site_name'] = \Drupal::config('system.site')->get('name');
$variables['baseURL'] = $GLOBALS['base_url'];
$variables['author'] = \Drupal::entityTypeManager()->getViewBuilder('user')->view($variables['node']->getOwner(), 'nodeview');
}
function milaniztheme_preprocess_node(&$variables) {
$variables['baseURL'] = $GLOBALS['base_url'];
}