This repository has been archived by the owner on Sep 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworkbench_tabs.module
77 lines (68 loc) · 1.81 KB
/
workbench_tabs.module
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
<?php
/**
* @file
* Drupal hooks.
*/
/**
* Implements hook_theme().
*/
function workbench_tabs_theme() {
return [
'workbench_tabs' => [
'render element' => 'element',
],
'workbench_tabs_menu_local_task' => [
'render element' => 'element',
],
'workbench_tabs_menu_local_tasks' => [
'variables' => ['primary' => NULL, 'secondary' => NULL],
],
'workbench_tabs_status_messages' => [
'variables' => ['status_headings' => [], 'message_list' => NULL],
],
];
}
/**
* Preprocess variables for the workbench_tabs_menu_local_task template.
*
* Wraps the core menu_local_task preprocess function.
*
* @ingroup themeable
*/
function template_preprocess_workbench_tabs_menu_local_task(&$variables) {
template_preprocess_menu_local_task($variables);
}
/**
* Preprocess variables for the workbench tabs template.
*
* @ingroup themeable
*/
function template_preprocess_workbench_tabs(&$variables) {
$element = $variables['element'];
$variables['messages'] = Drupal::service('renderer')->render($element['messages']);
$variables['tabs'] = Drupal::service('renderer')->render($element['tabs']);
$variables['has_messages'] = !empty($variables['messages']);
$variables['has_tabs'] = !empty($element['tabs']['#primary']);
}
/**
* Implements hook_page_top().
*/
function workbench_tabs_page_top(array &$page_top) {
$account = \Drupal::currentUser();
$page_top['workbench_tabs'] = [
'#theme' => 'workbench_tabs',
'#access' => $account->hasPermission('use workbench_tabs'),
];
$page_top['workbench_tabs']['messages'] = [
'#type' => 'workbench_tabs_status_messages',
'#cache' => [
'contexts' => [
'url.path',
'user.roles',
],
],
];
$page_top['workbench_tabs']['tabs'] = [
'#type' => 'workbench_tabs_local_tasks',
];
}