-
Notifications
You must be signed in to change notification settings - Fork 1
/
byu_theme.theme
executable file
·291 lines (248 loc) · 10.9 KB
/
byu_theme.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<?php
/**
* @file
* Bootstrap sub-theme.
*
* Place your custom PHP code in this file.
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Template\Attribute;
use Drupal\taxonomy\Entity\Term;
/**
* Implements hook_theme_suggestions_HOOK_alter().
*/
global $base_url;
$theme_root = $base_url.'/'.drupal_get_path('theme','byu_theme');
function byu_theme_preprocess_page(&$variables) {
global $base_url;
$theme_root = $base_url.'/'.drupal_get_path('theme','byu_theme');
$variables['theme_root'] = $theme_root;
$byu_theme_root = '/'.drupal_get_path('theme','byu_theme');
$variables['byu_theme_root'] = $byu_theme_root;
$user = \Drupal::currentUser()->id();
$account = \Drupal\user\Entity\User::load($user);
$name = $account->getUsername();
if($user){
$user = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
if($user->get('user_picture')->entity){
$picture = $user->get('user_picture')->entity->url();
}
}
$current_path = \Drupal::service('path.current')->getPath();
$path_args = explode('/', $current_path);
$variables['arg'] = $path_args[1];
//setting proper cache context for users
$variables['#cache']['contexts'][] = 'user';
$version = trim(theme_get_setting('components_version'));
if(!empty($version ) ) {
if($version == '1.x.x') {
$variables['#attached']['library'][] = 'byu_theme/components-1.x.x';
} elseif ($version == '1.2.x') {
$variables['#attached']['library'][] = 'byu_theme/components-1.2.x';
} elseif ($version == '1.3.x') {
$variables['#attached']['library'][] = 'byu_theme/components-1.3.x';
} elseif ($version == 'master') {
$variables['#attached']['library'][] = 'byu_theme/components-master';
} elseif ($version == 'latest') {
$variables['#attached']['library'][] = 'byu_theme/components-latest';
} elseif ($version == 'none') {
// don't attach components at all
}
$variables['#attached']['library'][] = 'byu_theme/custom-library';
} else { // setting wasn't set yet
$variables['#attached']['library'][] = 'byu_theme/components-latest';
}
/* --- Load Fonts ------- */
$fontawesome_use = trim(theme_get_setting('fontawesome_use'));
if($fontawesome_use == TRUE ) {
$variables['#attached']['library'][] = 'byu_theme/font-awesome';
}
$librebaskerville_use = trim(theme_get_setting('librebaskerville_use'));
if($librebaskerville_use == TRUE ) {
$variables['#attached']['library'][] = 'byu_theme/librebaskerville';
}
$sourcesans_use = trim(theme_get_setting('sourcesans_use'));
if($sourcesans_use == TRUE ) {
$variables['#attached']['library'][] = 'byu_theme/sourcesans';
}
/* ------ Load Helper Styles --------- */
$byu_buttons = trim(theme_get_setting('byu_buttons'));
if($byu_buttons == TRUE ) {
$variables['#attached']['library'][] = 'byu_theme/byu-buttons';
}
$byu_tables = trim(theme_get_setting('byu_tables'));
if($byu_tables == TRUE ) {
$variables['#attached']['library'][] = 'byu_theme/byu-tables';
}
$byu_box_shadows = trim(theme_get_setting('byu_box_shadows'));
if($byu_box_shadows == TRUE ) {
$variables['#attached']['library'][] = 'byu_theme/byu-box-shadows';
}
$userOb = $variables['user'];
// Load the site name out of configuration.
$config = \Drupal::config('system.site');
$variables['site_name'] = $config->get('name');
$variables['page_title'] = $variables['page']['#title'];
$variables['clients_top'] = views_embed_view('client', 'block_4');
$variables['current_url'] = $_SERVER['REQUEST_URI'];
$theme_root = $base_url.'/'.drupal_get_path('theme','byu_theme');
$variables['theme_root'] = $theme_root;
$libraries['#attached']['library'][] = 'herchel/global-styling';
$variables['logopath'] = file_url_transform_relative(file_create_url(theme_get_setting('logo.url')));
/* -- Load Theme settings ---- */
$variables['header_option'] = theme_get_setting('header_option');
$variables['subtitle_use'] = theme_get_setting('subtitle_use'); // t/f
$variables['subtitle_above'] = theme_get_setting('subtitle_above'); // t/f
$variables['subtitle_italic'] = theme_get_setting('subtitle_italic'); // t/f
$variables['subtitle_text'] = theme_get_setting('subtitle_text'); // text
// sign in
$variables['login_use'] = theme_get_setting('login_use'); // t/f
$variables['login_url'] = theme_get_setting('login_url');
$variables['logout_url'] = theme_get_setting('logout_url');
// my account stuff here
$variables['myaccount_use'] = theme_get_setting('myaccount_use'); // t/f
$variables['myaccount_url'] = theme_get_setting('myaccount_url');
// search
$variables['search_use'] = theme_get_setting('search_use');
$variables['search_submit'] = theme_get_setting('search_submit');
$variables['search_input'] = theme_get_setting('search_input');
// menu
$variables['menu_disable'] = theme_get_setting('menu_disable');
$variables['transparent'] = theme_get_setting('transparent');
// hero
$hero_setting = theme_get_setting('hero_width');
if($hero_setting == '0') {
$variables['hero_width'] = 'full-width';
} else {
$variables['hero_width'] = 'custom-width';
}
$hero_image_setting = theme_get_setting('hero_image_width');
if($hero_image_setting == '0') {
$variables['hero_image_width'] = '';
} else {
$variables['hero_image_width'] = 'full-width-images';
}
$hero_behind_setting = theme_get_setting('hero_vs_menu');
if($hero_behind_setting == '0') {
$variables['hero_vs_menu'] = 'hero-below-menu';
} else {
$variables['hero_vs_menu'] = 'hero-behind-menu';
}
// general page settings
$variables['full_width'] = theme_get_setting('full_width');
$variables['custom_width'] = theme_get_setting('custom_width');
$page_min_setting = theme_get_setting('min_page_height');
if($page_min_setting == 'none') {
$variables['min_page_height'] = 'no-min-height';
} elseif ($page_min_setting == '300') {
$variables['min_page_height'] = 'min-height-300';
} else {
$variables['min_page_height'] = 'min-height-500';
}
$variables['footer_option'] = theme_get_setting('footer_option');
$variables['footer_sticky'] = theme_get_setting('footer_sticky');
// $variables['footer_color_option'] = theme_get_setting('footer_color_option');
$variables['header_sticky_option'] = theme_get_setting('header_sticky_option');
$variables['page_header_option'] = theme_get_setting('page_header_option');
$variables['page_header_color_option'] = theme_get_setting('page_header_color_option');
$variables['below_slider_option'] = theme_get_setting('below_slider_option');
$variables['navigation_option'] = theme_get_setting('navigation_option');
$variables['contact_option'] = theme_get_setting('contact_option');
$variables['contact_about_link'] = theme_get_setting('contact_about_link');
$variables['contact_about'] = theme_get_setting('contact_about');
$variables['contact_us_link'] = theme_get_setting('contact_us_link');
$variables['contact_us'] = theme_get_setting('contact_us');
$variables['breadcrumbs'] = theme_get_setting('breadcrumbs');
}
function byu_theme_preprocess_html(&$variables) {
global $base_url;
$theme_root = $base_url.'/'.drupal_get_path('theme','byu_theme');
$variables['theme_root'] = $theme_root;
$current_path = \Drupal::service('path.current')->getPath();
$path_args = explode('/', $current_path);
$variables['arg'] = $path_args[1];
$variables['layout_option'] = theme_get_setting('layout_option');
$variables['header_option'] = theme_get_setting('header_option');
$variables['h_semi_transparent_option'] = theme_get_setting('h_semi_transparent_option');
$variables['skin_option'] = theme_get_setting('skin_option');
$variables['loader'] = theme_get_setting('loader');
$variables['your_css'] = theme_get_setting('your_css');
// general page
$full_width = 'full-width-' . theme_get_setting('full_width');
$min_page_height = 'min-height-' . theme_get_setting('min_page_height');
$variables['attributes']['class'][] = 'body';
$font_one = "h1-" . theme_get_setting('font_one');
$font_two = "h2-" . theme_get_setting('font_two');
$font_three = "h3-" . theme_get_setting('font_three');
$font_four = "h4-" . theme_get_setting('font_four');
$font_five = "h5-" . theme_get_setting('font_five');
$font_one_color = theme_get_setting('font_one_color');
$font_two_color = theme_get_setting('font_two_color');
$font_three_color = theme_get_setting('font_three_color');
$font_four_color = theme_get_setting('font_four_color');
$font_five_color = theme_get_setting('font_five_color');
$p_font = "p-" . theme_get_setting('p_font');
$variables['attributes'] = new Attribute($variables['attributes']);
$variables['attributes']->addClass([$font_one, $font_two, $font_three, $font_four, $font_five, $font_one_color, $font_two_color, $font_three_color, $font_four_color, $font_five_color, $p_font]);
// Determine whether or not this page is the homepage/front page. Add the appropriate class.
if (\Drupal::service('path.matcher')->isFrontPage()) {
$thisPage = 'front';
}
else {
$thisPage = 'not-front';
}
$variables['attributes']->addClass($thisPage);
// Get currently active user and his/her roles, user ID and whether or not this page is a user page.
$account = \Drupal::currentUser();
if ($variables['root_path'] == 'user') {
$variables['attributes']['class'][] = 'user-page';
$userId = $account->id();
$variables['attributes']['class'][] = 'user-id-' . $userId;
}
$roles = $account->getRoles();
foreach ($roles as $role) {
$variables['attributes']['class'][] = 'role-' . $role;
}
// Use the class term-# on term pages.
if ($variables['root_path'] == 'taxonomy') {
$vocab_names = taxonomy_vocabulary_get_names();
foreach ($vocab_names as $vocabulary) {
$query = \Drupal::entityQuery('taxonomy_term');
$query->condition('vid', $vocabulary);
$tids = $query->execute();
$terms = Term::loadMultiple($tids);
foreach ($terms as $term) {
if (taxonomy_term_is_page($term)) {
$termId = $term->id();
$termId = 'term-' . $termId;
$variables['attributes']->addClass($termId);
}
}
}
}
// Shows content type of the page. Also gives
$node = \Drupal::request()->attributes->get('node');
if ($node) {
if ($node instanceof Drupal\node\NodeInterface) {
$nodeId = $node->id();
$nodeId = "node-" . $nodeId;
$variables['attributes']->addClass($nodeId);
}
$contentType = $node->bundle();
$contentType = str_replace("_", "-", $contentType);
$contentType = "type-" . $contentType;
$variables['attributes']->addClass($contentType);
}
}
/**
* Implements hook_preprocess_user().
*/
function byu_theme_preprocess_user(&$variables) {
/** @var User $account */
$account = $variables['elements']['#user'];
$variables['username'] = $account->getDisplayName();
}
function byu_theme_preprocess_block(&$variables) {
}
function byu_theme_preprocess_region(&$variables) {
}