-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathis2_site_release_info.module
More file actions
61 lines (56 loc) · 1.6 KB
/
is2_site_release_info.module
File metadata and controls
61 lines (56 loc) · 1.6 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
<?php
/**
* @file
* Contains the hooks for this module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\is2_site_release_info\Callback\PreRenderCallback;
/**
* Implements hook_help().
*/
function is2_site_release_info_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.is2_site_release_info':
$output = '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('This module is a lightweight module and reads RELEASE.md file contents (if present) and showcases information in the Drupal toolbar section.') . '</p>';
return $output;
}
}
/**
* Implements hook_toolbar().
*/
function is2_site_release_info_toolbar():array {
$user = \Drupal::currentUser();
$items = [];
$items['release_version'] = [
'#cache' => [
'contexts' => [
'user.permissions',
'user.roles:anonymous',
],
],
];
if ($user->hasPermission('access shortcuts')) {
$items['release_version'] += [
'#type' => 'toolbar_item',
'tab' => [
'#lazy_builder' => [
'is2_site_release_info.toolbar_data_builder:renderReleaseInformation',
[],
],
'#create_placeholder' => TRUE,
],
'#wrapper_attributes' => [
'class' => [
'toolbar-item',
'release-info',
],
],
'#weight' => 9999,
];
}
// Remove the attribute field.
$items['release_version'] += \Drupal::service('plugin.manager.element_info')->getInfo('toolbar_item');
$items['release_version']['#pre_render'][] = [PreRenderCallback::class, 'removeTabAttributes'];
return $items;
}