-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdamo_theme.theme
More file actions
200 lines (187 loc) · 6.85 KB
/
damo_theme.theme
File metadata and controls
200 lines (187 loc) · 6.85 KB
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
<?php
/**
* @file
* Code for damo_theme.
*
* NOTE: If possible, put everything into the "src" folder.
* @see http://drupal-bootstrap.org/api/bootstrap/docs%21plugins%21README.md/group/plugins/8
*/
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;
/**
* Implements hook_preprocess_HOOK().
*/
function damo_theme_preprocess_html(&$variables) {
// Add latest IE render engine metatag.
$http_equiv = array(
'#type' => 'html_tag',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'x-ua-compatible',
'content' => 'ie=edge',
),
);
$variables['page']['#attached']['html_head'][] = [$http_equiv, 'http-equiv'];
}
/**
* Implements hook_preprocess_HOOK().
*/
function damo_theme_preprocess_page(&$variables) {
$routeMatch = Drupal::routeMatch();
$routeName = $routeMatch->getRouteName();
// @todo: General usage is broken and is shown on other pages, too.
if ($routeName === 'entity.media.canonical') {
$variables['#attached']['library'][] = 'damo_theme/media_page';
$variables['general_usage'] = 'visible';
}
if ($routeName === 'entity.media.delete_form' || $routeName === 'entity.media.edit_form') {
$variables['general_usage'] = 'hidden';
}
if ($routeName === 'entity.media.collection' || $routeName === 'view.unpublished_assets.unpublished_assets') {
$variables['#attached']['library'][] = 'damo_theme/front_page';
}
if ($routeName === 'entity.media.add_page') {
$variables['page']['#title'] = t('Add new content');
}
}
/**
* Implements hook_preprocess_page_title().
*/
function damo_theme_preprocess_page_title(&$variables) {
$routeMatch = Drupal::routeMatch();
if ($routeMatch->getRouteName() === 'entity.media.canonical') {
$variables['title'] = '';
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function damo_theme_preprocess_menu(&$variables) {
// If a menu link is expanded and has children, attach the dropdown library
// and exit the loop.
//
// @todo Move this somewhere, keep this file clean!
foreach ($variables['items'] as $key => $item) {
if ($item['is_expanded'] && !empty($item['below'])) {
$variables['#attached']['library'][] = 'bootstrap/dropdown';
break;
}
}
}
/**
* Implements hook_preprocess_HOOK().
*/
function damo_theme_preprocess_region__footer(&$variables) {
// @todo Move to BootstrapSetting or something.
// @see http://drupal-bootstrap.org/api/bootstrap/src%21Annotation%21BootstrapSetting.php/class/BootstrapSetting/8
$variables['site_name'] = Drupal::config('system.site')->get('name');
}
/**
* Implements hook_preprocess().
*/
function damo_theme_preprocess(&$variables, $hook) {
// Attach path variables to the base theme for all templates.
// Useful for including partials, because `directory` only refers to the
// path of the current theme, so in sub-themes it will not work as expected.
//
// @todo Move this to @BootstrapPreprocess class or other!
// @todo Add more variables.
$base_theme_path = base_path();
$base_theme_path .= \Drupal::service('extension.list.theme')
->getPath('damo_theme');
$variables['damo_base'] = [
'root' => $base_theme_path,
'logo' => $base_theme_path . '/logo.png', // @todo Don't hardcode .svg
'templates' => $base_theme_path . '/templates',
'partials' => $base_theme_path . '/templates/_partials',
'images' => $base_theme_path . '/images',
];
}
/**
* Implements hook_preprocess_image().
*/
function damo_theme_preprocess_image(&$variables) {
$current_route = Drupal::routeMatch();
$route = $current_route->getRouteName();
if ($route === 'entity.media.canonical') {
$variables['spotlight'] = TRUE;
}
}
function damo_theme_preprocess_media(&$variables) {
$variables['status'] = $variables['media']->isPublished();
$parameter = \Drupal::routeMatch()->getParameter('arg_0');
if ($parameter) {
// Load media collection.
$media_collection = \Drupal::entityTypeManager()
->getStorage('media_collection')
->load($parameter);
// Load media collection items.
$collection_items = $media_collection->get('items')->getValue();
foreach ($collection_items as $item) {
$items[] = $item['target_id'];
}
$media_collection_items = \Drupal::entityTypeManager()->getStorage('media_collection_item')->loadMultiple($items);
foreach ($media_collection_items as $c_item) {
if ($variables['mid'] === $c_item->get('media')->target_id) {
$style_id = $c_item->get('style')->getValue()[0]['target_id'];
// Get Style name.
$style = \Drupal::entityTypeManager()->getStorage('image_style')->load($style_id);
if ($style) {
$variables['content']['asset_type'] = $style->get('label');
}
$variables['attributes']['data-collection-item-uuid'] = $c_item->uuid();
$variables['attributes']['data-collection-uuid'] = $media_collection->uuid();
}
}
} else {
$route_name = \Drupal::routeMatch()->getRouteName();
if ($route_name === 'media_collection_share.collection.shared') {
$media_collection = \Drupal::entityTypeManager()->getStorage('shared_media_collection')->loadByProperties(['uuid' => \Drupal::routeMatch()->getParameter('uuid')]);
$media_collection = reset($media_collection);
$items = $media_collection->get('items')->getValue();
$item_ids = [];
foreach ($items as $item) {
$item_ids[] = $item['target_id'];
}
$query = \Drupal::entityQuery('media_collection_item')
->condition('id', $item_ids, 'IN')
->condition('media', $variables['mid'])
->accessCheck(FALSE);
$result = $query->execute();
$result = reset($result);
// Load collection item.
$collection_item = \Drupal::entityTypeManager()->getStorage('media_collection_item')->load($result);
$style_id = $collection_item->get('style')->getValue()[0]['target_id'];
$variables['content']['shared'] = TRUE;
if ($style_id) {
$style = \Drupal::entityTypeManager()->getStorage('image_style')->load($style_id);
$variables['content']['asset_type'] = $style->get('label');
$variables['content']['item_download_link'] = [
'#type' => 'link',
'#title' => new TranslatableMarkup('Download'),
'#url' => Url::fromRoute(
'media_collection_share.collection.shared.item_download',
[
'uuid' => $collection_item->uuid(),
]
),
'#attributes' => [
'class' => [
'btn',
'item-download-btn',
],
],
];
}
}
}
$route = \Drupal::routeMatch()->getRouteName();
if ($route === 'view.collection_view_page.collection_view') {
$variables['content']['link'] = TRUE;
}
if ($route === "view.collections.collections_page") {
$variables['content']['link'] = FALSE;
}
$variables['#cache'] = [];
$variables['#cache']['max-age'] = 0;
}