-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanblog.theme
417 lines (367 loc) · 16.1 KB
/
sanblog.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<?php
/**
* @file
* Functions to support theming in the Bartik theme.
*/
use Drupal\Core\Template\Attribute;
use Drupal\block\Entity\Block;
use Drupal\Core\Url;
$theme_path = drupal_get_path('theme', 'sanblog');
include_once $theme_path . '/includes/template_functions.php';
include_once $theme_path . '/includes/functions.php';
include_once $theme_path . '/includes/template_menu.php';
include_once $theme_path . '/includes/oembed.php';
include_once $theme_path . '/includes/override.php';
include_once $theme_path . '/includes/contact.php';
include_once $theme_path . '/customize/fonts.php';
function sanblog_preprocess_page(&$variables) {
global $base_url;
$theme_path = drupal_get_path('theme', 'sanblog');
$variables['#attached']['drupalSettings']['layzy_load'] = theme_get_setting('lazy_load');
$variables['footer_first_size'] = theme_get_setting('footer_first_size');
$variables['footer_second_size'] = theme_get_setting('footer_second_size');
$variables['footer_third_size'] = theme_get_setting('footer_third_size');
$variables['footer_four_size'] = theme_get_setting('footer_four_size');
$variables['pagetopmiddle_first_size'] = theme_get_setting('pagetopmiddle_first_size');
$variables['pagetopmiddle_second_size'] = theme_get_setting('pagetopmiddle_second_size');
$variables['pagetopmiddle_third_size'] = theme_get_setting('pagetopmiddle_third_size');
$variables['pagetopmiddle_four_size'] = theme_get_setting('pagetopmiddle_four_size');
$variables['college_name'] = theme_get_setting('college_name');
$variables['college_url'] = theme_get_setting('college_url');
$variables['site_number'] = theme_get_setting('site_number');
$variables['contact_url'] = theme_get_setting('contact_url');
$variables['sitemap_url'] = theme_get_setting('sitemap_url');
$variables['privacy_policy_url'] = theme_get_setting('privacy_policy_url');
$variables['site_accessibility_url'] = theme_get_setting('site_accessibility_url');
$variables['titleix_url'] = theme_get_setting('titleix_url');
$variables['facebook'] = theme_get_setting('facebook');
$variables['twitter'] = theme_get_setting('twitter');
$variables['skype'] = theme_get_setting('skype');
$variables['instagram'] = theme_get_setting('instagram');
$variables['linkedin'] = theme_get_setting('linkedin');
$variables['pinterest'] = theme_get_setting('pinterest');
$variables['github'] = theme_get_setting('github');
$variables['youtube'] = theme_get_setting('youtube');
$variables['vimeo'] = theme_get_setting('vimeo');
//Header setting -----------
$header = 'header';
if(theme_get_setting('default_header')){
$header = theme_get_setting('default_header');
}
if(isset($variables['gva_header']) && $variables['gva_header'] && $variables['gva_header']!='_none' ){
$header = $variables['gva_header'];
}
if(file_exists($theme_path . '/templates/page/' . trim($header) . '.html.twig')){
$variables['header_skin'] = $variables['directory'] . '/templates/page/' . trim($header) . '.html.twig';
}else{
$variables['header_skin'] = $variables['directory'] . '/templates/page/header.html.twig';
}
$variables['preloader'] = theme_get_setting('preloader');
$variables['theme_path'] = $base_url . '/' . $theme_path;
//Sticky Menu setting ---------
$variables['sticky_menu'] = '';
if(theme_get_setting('sticky_menu') == 1){
$variables['sticky_menu'] = 'gv-sticky-menu';
}
//Social setting -------------
//$custom_social_link = array();
//$custom_social_link['facebook'] = theme_get_setting('facebook');
//$custom_social_link['twitter'] = theme_get_setting('twitter');
//$custom_social_link['skype'] = theme_get_setting('skype');
//$custom_social_link['instagram'] = theme_get_setting('instagram');
//$custom_social_link['linkedin'] = theme_get_setting('linkedin');
//$custom_social_link['pinterest'] = theme_get_setting('pinterest');
//$custom_social_link['github'] = theme_get_setting('github');
//$custom_social_link['youtube'] = theme_get_setting('youtube');
//$custom_social_link['vimeo'] = theme_get_setting('vimeo');
//$variables['custom_social_link'] = $custom_social_link;
//Login form
$user = \Drupal::currentUser();
if($user){
$variables['custom_account'] = "Welcome <span class=\"text-theme\">{$user->getAccountName()}</span> (<a href=\"{$base_url}/user/logout\">Sign out</a>)";
}
$custom_link = array();
$custom_link['base_url'] = $base_url;
$custom_link['theme_path'] = $base_url . '/' . $theme_path;
$variables['custom_link'] = $custom_link;
}
/**
* Implements hook_preprocess_HOOK() for HTML document templates.
*
* Adds body classes if certain regions have content.
*/
function sanblog_preprocess_html(&$variables) {
global $theme, $base_url;
global $parent_root;
$theme_path = drupal_get_path('theme', 'sanblog');
//Customize
if(theme_get_setting('enable_panel') == '1' ){
$current_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$current_url = preg_replace('/([?&])display=[^&]+(&|$)/','$2',$current_url);
if(strpos($current_url, '?')){
$current_url .= '&';
}
else{
$current_url .= '?';
}
$variables['current_url'] = $current_url;
}
$tmp_logo = theme_get_setting('logo');
$variables['site_logo'] = $tmp_logo['url'];
$variables['theme_path'] = $base_url . '/' . $theme_path;
if(theme_get_setting('customize_css') ){
$custom_style = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', theme_get_setting('customize_css') );
$custom_style = str_replace( array( "\r\n", "\r", "\n", "\t", ' ', ' ', ' ' ), '', $custom_style );
$variables['customize_css'] = $custom_style;
}
//--- Customize sanblog ---
$customize_styles = '';
$json = '';
ob_start();
$json = \Drupal::config('gaviasthemer.settings')->get('gavias_customize');
if(!$json){
if(file_exists($theme_path . '/css/customize.json')){
$json = file_get_contents($theme_path . '/css/customize.json');
}
}
$variables['links_google_fonts'] = sanblog_links_typography_font($json);
require_once($theme_path . '/customize/dynamic_style.php');
$customize_styles = ob_get_clean();
$customize_styles = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $customize_styles );
$customize_styles = str_replace( array( "\r\n", "\r", "\n", "\t", ' ', ' ', ' ' ), '', $customize_styles );
$variables['customize_styles'] = $customize_styles;
//Form customize
$user = \Drupal::currentUser();
if(theme_get_setting('enable_customize') == 1 && \Drupal::moduleHandler()->moduleExists('gaviasthemer') && ($user->hasPermission('administer gavias_customize') || $user->hasPermission('administer gavias_customize preview')) ){
$url_customize_save = Url::fromRoute('gaviasthemer.admin.customize_save', array(), array('absolute' => TRUE))->toString();
$variables['#attached']['drupalSettings']['gavias_customize']['save'] = $url_customize_save;
$url_customize_preview = Url::fromRoute('gaviasthemer.admin.customize_preview', array(), array('absolute' => TRUE))->toString();
$variables['#attached']['drupalSettings']['gavias_customize']['preview'] = $url_customize_preview;
$variables['#attached']['library'][] = 'gaviasthemer/customize';
$variables['#attached']['drupalSettings']['gavias_customize']['json'] = $json;
$variables['addon_template'] = '';
$variables['save_customize_permission'] = 'hidden';
$variables['fonts'] = sanblog_render_option_font();
$variables['patterns'] = sanblog_options_patterns();
$variables['headerpatterns'] = sanblog_options_msuheader();
$variables['footerpatterns'] = sanblog_options_msufooter();
if(file_exists($theme_path . '/templates/addon/skins.html.twig')){
$variables['addon_template'] = $theme_path . '/templates/addon/skins.html.twig';
}
if($user->hasPermission('administer gavias_customize')){
$variables['save_customize_permission'] = 'show';
}
$current_url = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$current_url = preg_replace('/([?&])display=[^&]+(&|$)/','$2',$current_url);
if(strpos($current_url, '?')){
$current_url .= '&';
}
else{
$current_url .= '?';
}
$variables['current_url'] = $current_url;
}
//---- End customize gavias themer ---
$skin = 'default';
$skin = theme_get_setting('theme_skin');
if(isset($_GET['gvas']) && $_GET['gvas']){
$skin = $_GET['gvas'];
}
if(empty($skin)){
$skin = 'default';
}
if(\Drupal::service('module_handler')->moduleExists('gavias_hook_themer')){
$abs_url_config = Url::fromRoute('gavias_hook_themer.ajax_views', array(), array('absolute' => FALSE))->toString();
}else{
$abs_url_config = '';
}
$variables['#attached']['drupalSettings']['gavias_load_ajax_view'] = $abs_url_config;
$variables['#attached']['library'][] = 'gavias_batiz/gavias_batiz.skin.' . $skin;
// Add information about the number of sidebars.
if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
$variables['attributes']['class'][] = 'layout-two-sidebars';
}
elseif (!empty($variables['page']['sidebar_first'])) {
$variables['attributes']['class'][] = 'layout-one-sidebar';
$variables['attributes']['class'][] = 'layout-sidebar-first';
}
elseif (!empty($variables['page']['sidebar_second'])) {
$variables['attributes']['class'][] = 'layout-one-sidebar';
$variables['attributes']['class'][] = 'layout-sidebar-second';
}
else {
$variables['attributes']['class'][] = 'layout-no-sidebars';
}
if(theme_get_setting('preloader') == '1'){
$variables['attributes']['class'][] = 'js-preloader';
}else{
$variables['attributes']['class'][] = 'not-preloader';
}
if(theme_get_setting('site_layout') == 'boxed'){
$variables['attributes']['class'][] = 'boxed';
}
$layout = 'none';
$body_background = 'dark';
if ($node = \Drupal::request()->attributes->get('node')) {
if(is_object($node)){
if($node->hasField('gva_node_layout')){
$layout = $node->get('gva_node_layout')->value;
}
if($node->hasField('gva_body_background')){
if($node->get('gva_body_background')->value){
$body_background = $node->get('gva_body_background')->value;
}
}
}
}
$variables['attributes']['class'][] = 'layout-page-' . $layout;
$variables['attributes']['class'][] = 'body-background-' . $body_background;
}
/**
* Implements hook_preprocess_HOOK() for maintenance-page.html.twig.
*/
function sanblog_preprocess_maintenance_page(&$variables) {
if (!$variables['db_is_active']) {
$variables['site_name'] = '';
}
}
/**
* Implements hook_preprocess_HOOK() for block.html.twig.
*/
function sanblog_preprocess_block(&$variables) {
// Add a clearfix class to system branding blocks.
if ($variables['plugin_id'] == 'system_branding_block') {
$variables['attributes']['class'][] = 'clearfix';
$tmp_logo = theme_get_setting('logo');
$variables['setting_logo'] = $tmp_logo['use_default'];
}
}
function sanblog_preprocess_block__system_breadcrumb_block(&$variables){
$styles = array();
$bg_image = '';//base_path() . 'images/breadcrumb.jpg';
$bg_color = '#FFF';
$bg_position = 'center center';
$bg_repeat = 'no-repeat';
$text_style = 'text-dark';
if (!empty($variables['elements']['#id'])) {
$block = Block::load($variables['elements']['#id']);
if($variables['plugin_id'] == 'system_breadcrumb_block'){
$_id = $variables['elements']['#id'];
$breadcrumb_background_color = $block->getThirdPartySetting('gaviasthemer', 'breadcrumb_background_color');
$breadcrumb_background_position = $block->getThirdPartySetting('gaviasthemer', 'breadcrumb_background_position');
$breadcrumb_background_repeat = $block->getThirdPartySetting('gaviasthemer', 'breadcrumb_background_repeat');
$breadcrumb_color_style = $block->getThirdPartySetting('gaviasthemer', 'breadcrumb_color_style');
$breadcrumb_background_image_path = \Drupal::config('gaviasthemer.settings')->get('breadcrumb_background_image_path_' . $_id);
if($breadcrumb_color_style){
$text_style = $breadcrumb_color_style;
}
if($breadcrumb_background_color){
$bg_color = $breadcrumb_background_color;
}
if($breadcrumb_background_position){
$bg_position = $breadcrumb_background_position;
}
if($breadcrumb_background_repeat){
$bg_repeat = $breadcrumb_background_repeat;
}
if($breadcrumb_background_image_path){
$bg_image = file_create_url($breadcrumb_background_image_path);
}
}
}
$variables['attributes']['class'][] = $text_style;
$styles[] = "background-color: {$bg_color};";
if($bg_image){
$styles[] = "background-image: url('{$bg_image}');";
}
$styles[] = "background-position: {$bg_position};";
$styles[] = "background-repeat: {$bg_repeat};";
$variables['custom_style'] = implode('', $styles);
}
function sanblog_preprocess_image(&$variables) {
global $base_url;
if(theme_get_setting('lazy_load')=='on'){
if(isset($variables['attributes']['src'])){
$variables['attributes']['data-src'] = $variables['attributes']['src'];
$variables['attributes']['class'][] = 'unveil-image';
$variables['attributes']['src'] = '';//base_path() . drupal_get_path('theme', 'sanblog') .'/images/lazy_load.png';
}
}else{
if (isset($variables['attributes']['width']) && isset($variables['attributes']['height'])) {
unset($variables['attributes']['width']);
unset($variables['attributes']['height']);
}
}
}
/**
* Implements hook_preprocess_HOOK() for page templates.
*/
function sanblog_preprocess_page_title(&$variables) {
// Since the title and the shortcut link are both block level elements,
// positioning them next to each other is much simpler with a wrapper div.
if (!empty($variables['title_suffix']['add_or_remove_shortcut']) && $variables['title']) {
// Add a wrapper div using the title_prefix and title_suffix render
// elements.
$variables['title_prefix']['shortcut_wrapper'] = array(
'#markup' => '<div class="shortcut-wrapper clearfix">',
'#weight' => 100,
);
$variables['title_suffix']['shortcut_wrapper'] = array(
'#markup' => '</div>',
'#weight' => -99,
);
// Make sure the shortcut link is the first item in title_suffix.
$variables['title_suffix']['add_or_remove_shortcut']['#weight'] = -100;
}
}
/**
* Implements hook_theme_suggestions_HOOK_alter() for form templates.
*/
function sanblog_theme_suggestions_form_alter(array &$suggestions, array $variables) {
if ($variables['element']['#form_id'] == 'search_block_form') {
$suggestions[] = 'form__search_block_form';
}
}
/**
* Implements hook_form_alter() to add classes to the search form.
*/
/**
function sanblog_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if (in_array($form_id, ['search_block_form', 'search_form'])) {
$key = ($form_id == 'search_block_form') ? 'actions' : 'basic';
if (!isset($form[$key]['submit']['#attributes'])) {
$form[$key]['submit']['#attributes'] = new Attribute();
}
$form[$key]['submit']['#attributes']->addClass('search-form__submit');
}
}
*/
/**
function sanblog_theme_suggestions_page_alter(array &$suggestions, array $variables) {
if ($variables['element']['#form_id'] == 'search_block_form') {
$suggestions[] = 'form__search_block_form';
}
if ($node = \Drupal::request()->attributes->get('node')) {
if(is_object($node)){
if($node->hasField('gva_node_layout')){
$layout = $node->get('gva_node_layout')->value;
$variables['attributes']['class'][] = $layout;
if($layout){
array_splice($suggestions, 1, 0, 'page__layout__' . $layout);
}else{
array_splice($suggestions, 1, 0, 'page__node__' . $node->getType());
}
}else{
array_splice($suggestions, 1, 0, 'page__node__' . $node->getType());
}
}else{
array_splice($suggestions, 1, 0, 'page__node__full');
}
}
}
*/
function sanblog_theme_suggestions_field_alter(&$suggestions, $variables) {
$suggestions[] = 'field__' .
$variables['element']['#field_name'] . '__' .
$variables['element']['#view_mode'];
}