-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProcessDashboard.module
More file actions
103 lines (87 loc) · 3.4 KB
/
ProcessDashboard.module
File metadata and controls
103 lines (87 loc) · 3.4 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
95
96
97
98
99
100
101
102
103
<?php
/**
* Dashboard Module v 1.0.2
* Batch Editing and Creating of Pages in the ProcessWire Admin Panel
*
* @author Peter Burlingham (Pete)
* @copyright Peter Burlingham
* <http://www.notanotherdotcom.com>
*
* ProcessWire 2.x
* Copyright (C) 2011 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
* http://www.processwire.com
*
*/
class ProcessDashboard extends Process implements Module {
/**
* getModuleInfo is a module required by all modules to tell ProcessWire about them
*
* @return array
*
*/
public static function getModuleInfo() {
return array(
'title' => 'Process Dashboard',
'version' => 102,
'summary' => 'A custom dashboard page for the ProcessWire admin.',
'author' => 'Peter Burlingham',
'href' => '',
'singular' => true,
'autoload' => false,
'permission' => 'dashboard'
);
}
public function init() {
parent::init();
}
public function execute() {
// Redirect calls for the admin homepage to the dashboard (first child page)
if ($this->page->id == 2) {
$this->session->redirect($this->page->child->url);
}
###### You may edit below this line if you would like to create a normal Process module #######
$t = new TemplateFile($this->config->paths->siteModules . __CLASS__ . "/dashboard.php");
return $t->render();
}
public function ___install() {
// ProcessWire's admin page always has an ID of 2
$adminPage = $this->pages->get(2);
// We need to set the admin process to use this module's process so that it loads the first child page in the admin by default
$adminPage->process = __CLASS__;
$adminPage->save();
// Create the dashboard page (if it doesn't already exist)
if (!$adminPage->children('name=dashboard')->first()->id) {
$p = new Page();
$p->template = 'admin';
$p->title = 'Dashboard';
$p->name = 'dashboard';
$p->parent = $adminPage;
$p->process = __CLASS__;
$p->sort = 0; // Make sure it appears as the first in the list of pages under the admin
$p->save();
}
// Add a permission for new roles (other than superuser) to use so that they can log into the admin and see the dashboard
if (!$this->permissions->get('dashboard')->id) {
$permission = $this->permissions->add('dashboard');
$permission->title = 'User can view the admin dashboard. Required for roles other than superuser that need to access the admin when the dashboard is set as the default admin page.';
$permission->save();
}
}
public function ___uninstall() {
// ProcessWire's admin page always has an ID of 2
$adminPage = $this->pages->get(2);
// We need to set the admin process to use ProcessHome again (page list)
$adminPage->process = 'ProcessHome';
$adminPage->save();
// Delete dashboard page if it exists (we can only check by page name at present)
$dashboard = $adminPage->child('name=dashboard');
if ($dashboard->id) {
$dashboard->delete();
}
// Remove dashboard permissions
$perm = $this->permissions->get('dashboard');
$this->permissions->delete($perm);
}
}