-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffunctions_devel.module
More file actions
177 lines (161 loc) · 4.84 KB
/
ffunctions_devel.module
File metadata and controls
177 lines (161 loc) · 4.84 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/**
* @file
* Module file for dev utility module.
*/
/**
* Implements hook_menu().
*/
function ffunctions_devel_menu() {
$items = array();
// @todo: Make these %ffunctions_devel_entity_type_load/%ffunction_devel_entity__load?
$items['admin/ffunctions/devel/%/%'] = array(
// @todo: title callback based on entity type
'title' => 'Devel Load',
'page callback' => 'ffunctions_devel_load_page',
'page arguments' => array(3, 4),
'access arguments' => array('access devel information'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Wrapper around entity_load.
* @todo: this is only necessary if we use this for loading from the menu.
*
* @param string $entity_type
* The entity type to load, e.g. node or user.
* @param array $entity_ids
* An array of entity IDs.
*
* @return
* An array of entity objects indexed by their ids. When no results are
* found, an empty array is returned.
*
* @see entity_load().
*/
function ffunctions_devel_load($entity_type, $entity_ids) {
return entity_load($entity_type, $entity_ids);
}
/**
* Build a devel loaded object page.
*
* @see devel_load_object().
*/
function ffunctions_devel_load_page($entity_type, $entity_ids) {
module_load_include('pages.inc', 'devel');
if (!is_array($entity_ids)) {
$entity_ids = explode(',', $entity_ids);
}
$entities = ffunctions_devel_load($entity_type, $entity_ids);
return devel_load_object($entity_type, reset($entities));
}
/**
* Set up the configuration for local development.
*/
function ffunctions_devel_setup_dev_site() {
ffunctions_devel_disable_modules();
ffunctions_devel_enable_modules();
ffunctions_devel_variable_set();
ffunctions_devel_permissions_set();
ffunctions_devel_user_passwords_set();
drupal_flush_all_caches();
}
/**
* Invoke a hook and its alter.
*
* @param string $hook
* The name of the hook to invoke.
*
* @return array
* The compiled data from the hook that was invoked.
*/
function ffunctions_devel_invoke_hook($hook) {
$data = module_invoke_all($hook);
drupal_alter($hook, $data);
return $data;
}
/** Functions for setting up dev site **/
/**
* Get a list of modules to enable and do it.
*/
function ffunctions_devel_enable_modules() {
$modules = variable_get(__FUNCTION__, array());
if (!empty($modules)) {
module_enable($modules);
devel_set_message(t('Enabled modules @modules', array('@modules' => implode(', ', $modules))), 'ok');
}
}
/**
* Get a list of modules to disable and do it.
*/
function ffunctions_devel_disable_modules() {
$modules = variable_get(__FUNCTION__, array());
if (!empty($modules)) {
module_disable($modules);
devel_set_message(t('Disabled modules @modules', array('@modules' => implode(', ', $modules))), 'ok');
}
}
/**
* Set variable values.
*/
function ffunctions_devel_variable_set() {
$vars = variable_get('ffunctions_devel_variables', array(
'mail_system' => array(
'default-system' => 'DevelMailLog',
),
'error_level' => ERROR_REPORTING_DISPLAY_ALL,
'preprocess_css' => FALSE,
'preprocess_js' => FALSE,
));
if (!empty($vars)) {
foreach ($vars as $var => $value) {
variable_set($var, $value);
$message_value = (is_array($value) || is_object($value)) ? print_r($value, TRUE) : $value;
devel_set_message(t('Set variable @variable to @value', array('@variable' => $var, '@value' => $message_value)), 'ok');
}
}
}
/**
* Get a list of permissions to add/revoke.
*/
function ffunctions_devel_permissions_set() {
$perms = variable_get('ffunctions_devel_permissions', array(
'anonymous user' => array(
'access devel information' => 'access devel information',
'execute php code' => 'execute php code',
'switch users' => 'switch users',
),
'authenticated user' => array(
'access devel information' => 'access devel information',
'execute php code' => 'execute php code',
'switch users' => 'switch users',
),
));
// Write the updated permissions.
foreach (user_roles() as $rid => $role) {
if (isset($perms[$role])) {
user_role_change_permissions($rid, $perms[$role]);
devel_set_message(t('Set new permissions on role @role - @perms', array('@role' => $role, '@perms' => print_r($perms[$role], TRUE))), 'ok');
}
}
}
/**
* Set passwords on users.
*/
function ffunctions_devel_user_passwords_set() {
$accounts = variable_get('ffunctions_devel_user_passwords', array('admin' => 'admin'));
if (!empty($accounts)) {
foreach ($accounts as $name => $pass) {
$account = user_load_by_name($name);
if (!empty($account)) {
if (user_save($account, array('pass' => $pass))) {
devel_set_message(t('Set password on @name', array('@name' => $name)), 'ok');
}
else {
devel_set_message(t('Failed setting password on @name', array('@name' => $name)));
}
}
}
}
}