-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindigo.theme
65 lines (54 loc) · 1.92 KB
/
indigo.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* @file
* Preprocess functions for Cloud.
*/
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\taxonomy\Entity\Term;
/**
* Prepares variables for the html.html.twig template.
*/
function indigo_preprocess_html(&$variables) {
try {
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
}
catch (Exception $e) {
// If the database is not yet available, set default values for these
// variables.
$variables['is_front'] = FALSE;
}
// If we're on the front page.
if (!$variables['is_front']) {
// Add unique classes for each page and website section.
$path = \Drupal::service('path.current')->getPath();
$alias = \Drupal::service('path.alias_manager')->getAliasByPath($path);
$alias = trim($alias, '/');
$alias = str_replace('/', '-' , $alias);
if (!empty($alias)) {
$variables['attributes']['class'][] = 'page-' . $alias;
list($section, ) = explode('/', $alias, 2);
if (!empty($section)) {
$variables['attributes']['class'][] = 'section-' . $section;
}
}
}
// Add cachability metadata.
$theme_name = \Drupal::theme()->getActiveTheme()->getName();
$theme_settings = \Drupal::config($theme_name . '.settings');
CacheableMetadata::createFromRenderArray($variables)
->addCacheableDependency($theme_settings)
->applyTo($variables);
// Union all theme setting variables to the html.html.twig template.
$variables += $theme_settings->getOriginal();
}
function indigo_preprocess_page(&$variables) {
// Load the site name out of configuration.
$config = \Drupal::config('system.site');
$node_types = \Drupal::entityTypeManager()
->getStorage('node_type')
->loadMultiple();
$variables['node_types'] = $node_types;
$variables['site_name'] = $config->get('name');
$variables['site_slogan'] = $config->get('slogan');
$variables['theme_logo'] = file_get_contents(__DIR__ . '/' . 'logo.svg');
}