generated from SU-SWS/stanford_starter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vpue_undergrad_subtheme.theme
executable file
·98 lines (79 loc) · 3.25 KB
/
vpue_undergrad_subtheme.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @file
* Preprocess functions for Stanford Starter.
*/
/**
* Prepares variables for the html.html.twig template.
*/
function vpue_undergrad_subtheme_preprocess_html(&$variables) {
$variables['stanford_basic_path'] = \Drupal::service('extension.list.theme')->getPath('stanford_basic');
}
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
function vpue_undergrad_subtheme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
if (!empty($variables['elements']['#id']) && $variables['elements']['#id'] == 'vpue_undergrad_subtheme_search') {
$suggestions[] = 'block__stanford_basic_search';
}
}
/**
* Prepares variable for the front page to have the banner effect.
*/
function vpue_undergrad_subtheme_preprocess_field__su_page_banner(&$variables) {
if (\Drupal::service('path.matcher')->isFrontPage()) {
$variables['items'][0]['content']['#is_front'] = TRUE;
}
}
/**
* Prepares variables for the paragraph - mainly used when editing the paragraph
* Implements hook_preprocess_HOOK().
*/
function vpue_undergrad_subtheme_preprocess_ds_entity_view(&$variables) {
// if not running on a paragraph, exit out.
if (!isset($variables['content']['#paragraph'])){
return;
}
$paragraph = $variables['content']['#paragraph'];
// Process Banners
if ( $paragraph->bundle() == 'stanford_banner') {
vpue_undergrad_subtheme_preprocess_banner($variables);
}
// Is front page variable
if (!empty($variables['content']['#is_front']) && $variables['content']['#is_front']) {
$variables['content']['#variant'] = 'front';
}
}
/**
* Setting the unique name for the banner on the front page.
*/
function vpue_undergrad_subtheme_preprocess_pattern_hero(&$variables) {
if ($variables['variant'] == 'front') {
$variables['variant'] = 'default';
$variables['is_front'] = TRUE;
}
}
/**
* Adding classes for the banners.
*/
function vpue_undergrad_subtheme_preprocess_banner(&$variables) {
// If banner has an image, add a class
if(isset($variables['content']['#fields']['hero_image']['su_banner_image']['#object']) ) {
$variables['attributes']['class'][] = 'vpue-hero-banner--has-image';
// Banners use 'full_responsive' mode already. This is a placeholder to use this line once a responsive 1:1 ratio style exists in our d8core
// $variables['content']['#fields']['hero_image']['su_banner_image'][0]['#stanford_media_image_style'] = 'full_responsive';
// Check if there is a card
if(isset($variables['content']['#fields']['hero_super_headline']['su_banner_sup_header']['#object']) || isset($variables['content']['#fields']['hero_headline']['su_banner_header']['#object']) || isset($variables['content']['#fields']['hero_body']['su_banner_body']['#object']) ) {
$variables['attributes']['class'][] = 'vpue-hero-banner--has-card';
} else {
$variables['attributes']['class'][] = 'vpue-hero-banner--no-card';
}
// Check if on the homepage and use different banner twig file.
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
if ($variables['is_front'] === TRUE) {
$variables['attributes']['class'][] = 'vpue-hero-banner--has-image-on-homepage';
}
} else {
$variables['attributes']['class'][] = 'vpue-hero-banner--no-image';
}
}