-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfpe.theme
55 lines (49 loc) · 1.65 KB
/
fpe.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
<?php
/**
* @file
* Preprocess functions for Basic.
*/
use Drupal\Core\Cache\CacheableMetadata;
/**
* Prepares variables for the html.html.twig template.
*/
function fpe_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, '/');
if (!empty($alias)) {
$name = str_replace('/', '-', $alias);
$variables['attributes']['class'][] = 'page-' . $name;
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();
}
/**
* Prepares variables for the field.html.twig template.
*/
function fpe_preprocess_field(&$variables, $hook) {
// Make additional variables available to the template.
$variables['bundle'] = $variables['element']['#bundle'];
}