-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsustainable.theme
56 lines (46 loc) · 1.7 KB
/
sustainable.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
<?php
/**
* @file
* cuenergy sub-theme.
*
* Place your custom PHP code in this file.
*/
/**
* Implements hook_preprocess_html().
*/
function sustainable_preprocess_html(&$variables) {
$current_path = \Drupal::service('path.current')->getPath();
$path_alias = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);
$path_alias = ltrim($path_alias, '/');
$variables['attributes']['class'][] = 'path-' . \Drupal\Component\Utility\Html::cleanCssIdentifier($path_alias);
if ($node = \Drupal::request()->attributes->get('node')) {
$variables['attributes']['class'][] = 'page-node-' . $node->id();
}
}
function sustainable_theme_suggestions_page_alter(&$suggestions, $variables) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$type = $node->getType();
$suggestions[] = 'page__content_type__' . $type;
}
}
function sustainable_preprocess_page(&$variables) {
if (array_key_exists('node', $variables)) {
$node = $variables['node'];
if (isset($node) && !is_string($node)) {
if ($node->hasField('field_hero_background')) {
$images = $node->get('field_hero_background');
if (sizeof($images) === 0) {
$image = $images->getFieldDefinition();
$defaultImage = $image->getSetting('default_image');
$entityrepository = Drupal::service('entity.repository');
$defaultImageFile = $entityrepository->loadEntityByUuid('file', $defaultImage['uuid']);
if($defaultImageFile) {
$defaultImageUri = $defaultImageFile->getFileUri();
$defaultImage['fileuri'] = $defaultImageUri;
$image->setSetting('default_image', $defaultImage);
}
}
}
}
}
}