-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworkbench.module
93 lines (87 loc) · 2.37 KB
/
workbench.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* @file
* Workbench module file.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\workbench\Render\Element\WorkbenchToolbar;
use Drupal\Core\Url;
/**
* Implements hook_help().
*/
function workbench_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.workbench':
$text = file_get_contents(dirname(__FILE__) . '/README.md');
if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
return workbench_parse_help($text);
}
else {
// Use the Markdown filter to render the README.
$filter_manager = \Drupal::service('plugin.manager.filter');
$settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
$config = ['settings' => $settings];
$filter = $filter_manager->createInstance('markdown', $config);
return $filter->process($text, 'en');
}
}
return NULL;
}
/**
* Implements hook_toolbar().
*/
function workbench_toolbar() {
// The 'Workbench' tab is a simple link, with no corresponding tray.
$user = \Drupal::currentUser();
$items = [];
if ($user->hasPermission('access workbench')) {
$items['workbench'] = [
'#type' => 'toolbar_item',
'tab' => [
'#type' => 'link',
'#title' => t('Workbench'),
'#url' => Url::fromRoute('workbench.content'),
'#attributes' => [
'title' => t('My personal editorial workspace'),
'class' => ['toolbar-icon', 'toolbar-icon-workbench-content-tab'],
],
],
'tray' => [
'#heading' => t('Your Workbench'),
'workbench_toolbar' => [
'#pre_render' => [
[WorkbenchToolbar::class, 'preRenderTray'],
],
],
'#type' => 'container',
],
'#attached' => [
'library' => [
'workbench/workbench.toolbar',
],
],
'#weight' => -18,
];
}
return $items;
}
/**
* Simplified display of help text without markdown module.
*
* @param $text
* The help text markdown.
*
* @return HTML
*/
function workbench_parse_help($text) {
$find = "```\n\n";
$replace = '</pre>';
$text = str_replace($find, $replace, $text);
$find = "```";
$replace = '<pre>';
$text = str_replace($find, $replace, $text);
$find = ["\n"];
$replace = ['<br />'];
$text = str_replace($find, $replace, $text);
return $text;
}