-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugModeSwitch.module
More file actions
94 lines (89 loc) · 2.71 KB
/
DebugModeSwitch.module
File metadata and controls
94 lines (89 loc) · 2.71 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
<?php namespace ProcessWire;
/**
* Debug Mode Switch
* Enables the debug mode to bypass the restriction to install modules.
*
* @author tech-c.net
* @license Licensed under GNU/GPL v2
* @link https://tech-c.net/posts/debug-mode-switch-for-processwire/
* @version 1.0.1
*
* @see Forum Thread: https://processwire.com/talk/topic/26892-debug-mode-switch-for-processwire/
* @see Donate: https://tech-c.net/donation/
*/
class DebugModeSwitch extends WireData implements Module, ConfigurableModule {
/**
* Return information about this module
*/
public static function getModuleInfo() {
return array(
'title' => 'Debug Mode Switch',
'summary' => 'Enables the debug mode to bypass the restriction to install modules.',
'href' => 'https://tech-c.net/posts/debug-mode-switch-for-processwire/',
'author' => 'tech-c.net',
'version' => 101,
'icon' => 'bug',
'autoload' => true,
'singular' => true);
}
/**
* Instance of module
*/
public function __construct() {
foreach(self::getDefaultData() as $key => $value) {
$this->$key = $value;
}
}
/**
* Default configuration for module
*/
static public function getDefaultData() {
return array(
'active' => 0,
'superuser' => 1
);
}
/**
* Module settings
*/
static public function getModuleConfigInputfields(array $data) {
$fields = new InputfieldWrapper();
$modules = wire('modules');
$defaults = self::getDefaultData();
$data = array_merge($defaults, $data);
$field = $modules->get('InputfieldCheckbox');
$field->name = 'active';
$field->label = __('Debug Mode');
$field->description = __('Enables the debug mode.');
$field->attr('name', 'active');
$field->attr('checked', $data['active'] ? 'checked' : '');
$field->label2 = __('Enabled');
$fields->add($field);
$field = $modules->get('InputfieldCheckbox');
$field->name = 'superuser';
$field->label = __('Only for Superusers');
$field->description = __('Restricts the debug mode to superusers only.');
$field->attr('name', 'superuser');
$field->attr('checked', $data['superuser'] ? 'checked' : '');
$field->label2 = __('Enabled');
$fields->add($field);
return $fields;
}
/**
* Initialize the module
*/
public function init() {
$data = $this->modules->getModuleConfigData($this->className);
$defaults = $this->modules->get($this->className)->getDefaultData();
$data = array_merge($defaults, $data);
if ($data['active'] == '1') {
if ($data['superuser'] == '1') {
if ($this->user->hasRole('superuser')) {
$this->config->debug = true;
}
} else {
$this->config->debug = true;
}
}
}
}