-
Notifications
You must be signed in to change notification settings - Fork 10
/
carapace.theme
172 lines (158 loc) · 4.66 KB
/
carapace.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
<?php
/**
* @file
* Functions to support theming in the Carapace theme.
*/
use Drupal\Component\Utility\Xss;
use Drupal\Component\Utility\Html;
/**
* Add dynamic library definitions.
*
* Modules may implement this hook to add dynamic library definitions. Static
* libraries, which do not depend on any runtime information, should be declared
* in a modulename.libraries.yml file instead.
*
* @return array[]
* An array of library definitions to register, keyed by library ID. The
* library ID will be prefixed with the module name automatically.
*
* @see core.libraries.yml
* @see hook_library_info_alter()
*/
function carapace_library_info_build() {
$libraries = [];
$theme = 'carapace';
$theme_registry = \Drupal::service('theme.registry')->get();
$config = \Drupal::config($theme . '.settings')->get('settings');
// Layout libraries.
$libraries[$theme . '.layout.page'] = [
'css' => [
'layout' => [
'styles/css/generated/' . $theme . '.layout.page.css' => [],
],
],
];
foreach ($theme_registry as $key => $values) {
if (substr($key, 0, 6) == 'page__') {
$suggestion = str_replace('_', '-', $key);
$libraries[$theme . '.layout.' . $key] = [
'css' => [
'layout' => [
'styles/css/generated/' . $theme . '.layout.' . $suggestion . '.css' => [],
],
],
];
}
}
// Extension libraries.
if (isset($config['enable_extensions']) && $config['enable_extensions'] === 1) {
// Fonts.
if (isset($config['enable_fonts']) && $config['enable_fonts'] === 1) {
// Google fonts.
if (!empty($config['font_google'])) {
$libraries['google_fonts'] = [
'remote' => 'https://www.google.com/fonts',
'license' => [
'name' => 'SIL (OFL)',
'url' => 'http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=OFL',
'gpl-compatible' => TRUE,
],
'css' => [
'base' => [
Xss::filter($config['font_google']) => [],
],
],
'weight' => -1000,
];
}
// Typekit.
if (!empty($config['font_typekit'])) {
$libraries['typekit_id'] = [
'remote' => '//use.typekit.net/',
'license' => [
'name' => 'Apache 2.0',
'url' => 'http://www.apache.org/licenses/LICENSE-2.0',
'gpl-compatible' => TRUE,
],
'js' => [
'//use.typekit.net/' . Html::escape($config['font_typekit']) . '.js' => ['type' => 'external'],
],
'header' => TRUE,
];
}
}
}
return $libraries;
}
/**
* 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 carapace_page_attachments_alter(array &$page) {
$theme = 'carapace';
// Attach module dependant libraries.
// These libraries are declared in your themeName.libraries.yml and we only
// load if the module is installed.
$module_libraries = [
'addtoany',
'ds',
'social_media_links',
'superfish',
];
$theme_libraries = \Drupal::service('library.discovery')->getLibrariesByExtension($theme);
foreach ($module_libraries as $module_library) {
if (array_key_exists($module_library, $theme_libraries) && \Drupal::moduleHandler()->moduleExists($module_library) === TRUE) {
$page['#attached']['library'][] = "$theme/$module_library";
}
}
}
/**
* Preprocess variables for html templates.
*/
/* -- Delete this line if you want to use this function
function carapace_preprocess_html(&$variables) {
}
*/
/**
* Preprocess variables for page templates.
*/
/* -- Delete this line if you want to use this function
function carapace_preprocess_page(&$variables) {
}
*/
/**
* Preprocess variables for field templates.
*/
/* -- Delete this line if you want to use this function
function carapace_preprocess_field(&$variables) {
}
*/
/**
* Preprocess variables for node templates.
*/
/* -- Delete this line if you want to use this function
function carapace_preprocess_node(&$variables) {
}
*/
/**
* Preprocess variables for comment templates.
*/
/* -- Delete this line if you want to use this function
function carapace_preprocess_comment(&$variables) {
}
*/
/**
* Preprocess variables for block templates.
*/
/* -- Delete this line if you want to use this function
function carapace_preprocess_block(&$variables) {
}
*/