-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugbar.module
136 lines (122 loc) · 3.53 KB
/
debugbar.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
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
<?php
/**
* Implements hook_init().
*/
function debugbar_init() {
$c = pimple_get_container();
$c['debugbar'];
}
/**
* Implements hook_menu().
*/
function debugbar_menu() {
$items['vendor/maximebf/debugbar/src/DebugBar/Resources'] = array(
'title' => 'Debugbar',
'page callback' => 'debugbar_asset',
'access callback' => TRUE,
'file' => 'debugbar.pages.inc',
'type' => MENU_CALLBACK,
);
$items['debugbar/open'] = array(
'title' => 'Debugbar',
'page callback' => 'debugbar_open',
'access arguments' => array('access php debug bar'),
'file' => 'debugbar.pages.inc',
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_permission().
*/
function debugbar_permission() {
return array(
'access php debug bar' => array(
'title' => t('Access PHP Debug Bar'),
),
);
}
/**
* Implements hook_page_build().
*/
function debugbar_page_build(&$page) {
$page['page_bottom']['debugbar'] = array(
'debugbar' => array(
'#markup' => \DebugBar\JavascriptRenderer::REPLACEABLE_TAG,
'#access' => user_access('access php debug bar'),
),
);
}
/**
* Implements hook_page_delivery_callback_alter().
*/
function debugbar_page_delivery_callback_alter(&$callback) {
if ($callback === 'ajax_deliver') {
$c = pimple_get_container();
$c['debugbar.renderer']->render(false);
}
}
/**
* Implements hook_process_html().
*/
function debugbar_process_html(&$variables) {
$c = pimple_get_container();
if (user_access('access php debug bar')) {
$variables['head'] = $c['debugbar.renderer']->renderHead() . $variables['head'];
}
}
/**
* Implements hook_form_alter().
*/
function debugbar_form_alter(&$form, &$form_state, $form_id) {
$c = pimple_get_container();
$collector = new \DebugBar\DataCollector\ConfigCollector(array('form' => $form, 'form_state' => $form_state), $form_id);
$c['debugbar']->addCollector($collector);
}
/**
* Implements hook_watchdog().
*/
function debugbar_watchdog(array $log_entry) {
static $level_map = array(
WATCHDOG_EMERGENCY => \Psr\Log\LogLevel::EMERGENCY,
WATCHDOG_ALERT => \Psr\Log\LogLevel::ALERT,
WATCHDOG_CRITICAL => \Psr\Log\LogLevel::CRITICAL,
WATCHDOG_ERROR => \Psr\Log\LogLevel::ERROR,
WATCHDOG_WARNING => \Psr\Log\LogLevel::WARNING,
WATCHDOG_NOTICE => \Psr\Log\LogLevel::NOTICE,
WATCHDOG_INFO => \Psr\Log\LogLevel::INFO,
WATCHDOG_DEBUG => \Psr\Log\LogLevel::DEBUG,
);
$c = pimple_get_container();
$debugbar = $c['debugbar'];
$message = strip_tags(!isset($log_entry['variables']) ? $log_entry['message'] : strtr($log_entry['message'], $log_entry['variables']));
$debugbar['messages']->log($level_map[$log_entry['severity']], $message, $log_entry);
}
/**
* Implements hook_drupal_goto_alter().
*/
function debugbar_drupal_goto_alter($path, $options, $http_response_code) {
if (isset($path)) {
$c = pimple_get_container();
/** @var \DebugBar\DebugBar $debugbar */
$debugbar = $c['debugbar'];
if (!$debugbar->getHttpDriver()->isSessionStarted()) {
drupal_session_start();
}
$debugbar->stackData();
}
}
/**
* Implements hook_page_alter().
*/
function debugbar_page_alter(&$page) {
$page['#post_render'][] = 'debugbar_page_token_processing';
}
/**
* Post-render function inserts debugbar as late as possible.
*/
function debugbar_page_token_processing($children, $elements) {
$c = pimple_get_container();
$replace_pairs = array(\DebugBar\JavascriptRenderer::REPLACEABLE_TAG => $c['debugbar.renderer']->render());
return strtr($children, $replace_pairs);
}