forked from jacerider/fett
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fett.theme
138 lines (121 loc) · 3.98 KB
/
fett.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
<?php
/**
* @file
* Functions to support theming in Fett.
*/
include_once __DIR__ . '/includes/fett.offcanvas.php';
include_once __DIR__ . '/includes/fett.mobile_menu.php';
/**
* Implements hook_theme().
*/
function fett_theme() {
$module_path = drupal_get_path('theme', 'fett');
return [
] + fett_offcanvas_theme($module_path);
}
/**
* Implements hook_theme_registry_alter().
*/
function fett_theme_registry_alter(&$theme_registry) {
// Add another page preprocess function that will get called after all child
// theme preprocess functions.
$theme_registry['page']['preprocess functions'][] = 'fett_preprocess_page_last';
}
/**
* Implements hook_html_head_alter().
*/
function fett_html_head_alter(&$head_elements) {
// HTML5 charset declaration.
$head_elements['system_meta_content_type']['#attributes'] = array(
'charset' => 'utf-8',
);
// Optimize mobile viewport.
$head_elements['mobile_viewport'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'name' => 'viewport',
'content' => 'width=device-width, initial-scale=1',
),
);
}
/**
* Implements hook_library_info_alter().
*/
function fett_library_info_alter(&$libraries, $extension) {
$active_theme = \Drupal::theme()->getActiveTheme();
$theme = $active_theme->getName();
if ($extension == 'fett' && $theme !== 'fett') {
// Use subtheme vender javascript if it exists.
$theme_path = $active_theme->getPath();
foreach ($libraries as &$library) {
if (!empty($library['bower'])) {
if (!empty($library['js'])) {
foreach ($library['js'] as $file => $data) {
$new_path = $theme_path . '/' . $file;
if (file_exists($new_path)) {
$library['js']['/' . $new_path] = $data;
unset($library['js'][$file]);
}
}
}
}
}
}
}
/**
* Alter attachments (typically assets) to a page before it is rendered.
*
* Use this hook when you want to remove or alter attachments on the page, or
* add attachments to the page that depend on another module's attachments (this
* hook runs after hook_page_attachments().
*
* @param array &$page
* An empty renderable array representing the page.
*
* @see hook_page_attachments_alter()
*/
function fett_page_attachments_alter(array &$page) {
$active_theme = \Drupal::theme()->getActiveTheme();
$theme = $active_theme->getName();
$theme_path = $active_theme->getPath();
$config = \Drupal::config($theme . '.settings')->get('settings');
// Process extension settings.
if (isset($config['enable_extensions']) && $config['enable_extensions'] === 1) {
// Attach poly-fills to support IE8.
if (isset($config['enable_legacy_browsers']) && $config['enable_legacy_browsers'] === 1) {
if (isset($config['legacy_browser_polyfills']) && $config['legacy_browser_polyfills'] === 1) {
$page['#attached']['library'][] = 'fett/fett.html5shiv';
$page['#attached']['library'][] = 'fett/fett.respond';
$page['#attached']['library'][] = 'fett/fett.selectivizr';
}
}
}
}
/**
* Implements hook_preprocess_page().
*/
function fett_preprocess_page(&$vars) {
$theme = \Drupal::theme()->getActiveTheme()->getName();
$config = \Drupal::config($theme . '.settings')->get('settings');
$vars['prefix'] = isset($vars['prefix']) ? $vars['prefix'] : [];
$vars['suffix'] = isset($vars['suffix']) ? $vars['suffix'] : [];
$vars['attributes'] = isset($vars['attributes']) ? $vars['attributes'] : [];
// Mobile menu ops
fett_mobile_menu_preprocess_page($vars, $config);
}
/**
* This page preprocess function will be called after all other preprocessing
* has been completed.
*/
function fett_preprocess_page_last(&$vars) {
$theme = \Drupal::theme()->getActiveTheme()->getName();
$config = \Drupal::config($theme . '.settings')->get('settings');
// Offcanvas ops
fett_offcanvas_preprocess_page($vars, $config);
}
/**
* Implements hook_preprocess_html().
*/
function fett_preprocess_html(&$vars) {
}