This repository has been archived by the owner on Feb 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bear_skin.theme
174 lines (152 loc) · 5.85 KB
/
bear_skin.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
<?php
/**
* @file
* Functions to support theming in the bear_skin theme.
*/
/**
* Implements hook_preprocess_html().
*/
function bear_skin_preprocess_html(&$variables, $hook) {
// Add variables and paths needed for HTML5 and responsive support.
$variables['base_path'] = base_path();
$variables['path_to_bear_skin'] = drupal_get_path('theme','bear_skin');
$variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
// Add a class that tells us whether the page is viewed by an authenticated user or not.
$variables['attributes']['class'][] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in';
// if the sticky footer option is selected, set a class
if (theme_get_setting('sticky_footer')) {
$variables['attributes']['class'][] = 'sticky-footer';
}
// adding classes for basic layouts
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';
}
}
/**
* Implements hook_preprocess_region().
*/
function bear_skin_preprocess_region(&$variables) {
$variables['attributes']['class'][] = 'region';
$variables['attributes']['class'][] = 'region--' . $variables['elements']['#region'];
}
/**
* Implements hook_preprocess_block().
*/
function bear_skin_preprocess_block(&$variables) {
// All blocks get block and block__title classes.
$variables['attributes']['class'][] = 'block';
$variables['title_attributes']['class'][] = 'block__title';
// plugin_id => class
$map = array(
// Site branding block.
'system_branding_block' => 'block--branding',
// Search form block.
'search_form_block' => 'block--search-form',
// Page title block.
'page_title_block' => 'block--page-title',
// Status messages block.
'system_messages_block' => 'block--messages',
// Tabs block.
'local_tasks_block' => 'block--local-tasks',
// Main page content block.
'system_main_block' => 'block--main',
// Powered by Drupal block.
'system_powered_by_block' => 'block--powered-by'
);
if (array_key_exists($variables['plugin_id'], $map)) {
// Block found in map.
$variables['attributes']['class'][] = $map[$variables['plugin_id']];
}
elseif (substr($variables['plugin_id'], 0, 18) === 'system_menu_block:') {
// Menu blocks, including main navigation.
$variables['attributes']['class'][] = 'nav';
$variables['attributes']['class'][] = 'nav--' . substr($variables['plugin_id'], 18);
}
}
/**
* Implements hook_preprocess_HOOK() for page-title.html.twig.
*/
function bear_skin_preprocess_page_title(&$variables) {
$variables['title_attributes']['class'][] = 'page-title';
}
/**
* Implements hook_preprocess_HOOK() for status-messages.html.twig.
*/
function bear_skin_preprocess_status_messages(&$variables) {
$variables['attributes']['class'][] = 'messages';
}
/**
* Implements hook_pre_render_HOOK() for menu-local-tasks templates.
*
* Use preprocess hook to convert menu_local_task into variables needed by the
* tabs component.
*/
function bear_skin_preprocess_menu_local_tasks(&$variables) {
foreach (array('primary', 'secondary') as $type) {
$tabs = array();
// Sort the tabs by #weight.
uasort($variables[$type], array('Drupal\Component\Utility\SortArray', 'sortByWeightProperty'));
foreach (array_keys($variables[$type]) as $key) {
// Add the tab to a new array.
$tabs[$key] = array(
'active' => $variables[$type][$key]['#active'],
'url' => $variables[$type][$key]['#link']['url']->toString(),
'text' => \Drupal\Component\Utility\Html::escape($variables[$type][$key]['#link']['title'])
);
// Check if the tab should be shown by rendering the original.
$link = drupal_render($variables[$type][$key]);
if (!$link) {
unset($tabs[$key]);
}
}
// Overwrite the original tabs data.
$variables[$type] = $tabs;
}
}
/**
* Implements hook_preprocess_HOOK() for node.html.twig.
*/
function bear_skin_preprocess_node(&$variables) {
$variables['attributes']['class'][] = 'node';
$variables['attributes']['class'][] = 'node--' . $variables['node']->getType();
$variables['attributes']['class'][] = $variables['view_mode'];
if ($variables['view_mode'] !== 'page') {
$variables['title_attributes']['class'][] = 'node__title';
}
}
function bear_skin_preprocess_links__node(&$variables) {
$variables['attributes']['class'][] = 'node__links';
}
function bear_skin_preprocess_views_view(&$variables) {
$variables['attributes']['class'][] = 'view';
$variables['attributes']['class'][] = 'view--' . $variables['css_name'];
}
function bear_skin_preprocess_field(&$variables) {
$variables['attributes']['class'][] = 'field';
$variables['attributes']['class'][] = 'field--' . $variables['field_name'];
$variables['title_attributes']['class'][] = 'field--comment__title';
}
function bear_skin_preprocess_comment(&$variables) {
$variables['attributes']['class'][] = 'comment';
$variables['title_attributes']['class'][] = 'comment__title';
$url = $variables['elements']['#comment']->permalink();
$options = $url->getOptions();
$options['attributes']['class'][] = 'comment__permalink';
$url->setOptions($options);
$variables['permalink'] = \Drupal::l(t('Permalink'), $url);
$variables['content_attributes']['class'][] = 'comment__content';
}
function bear_skin_preprocess_form(&$variables) {
$variables['attributes']['class'][] = 'form';
}