1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Variable API module - Admin UI
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
/**
|
8 |
|
|
* Variable overview, by group
|
9 |
|
|
*/
|
10 |
|
|
function variable_admin_page_group($group = NULL) {
|
11 |
|
|
variable_include();
|
12 |
|
|
$build['message']['#markup'] = _variable_admin_realm_message();
|
13 |
|
|
$realm_options = _variable_admin_realm_options();
|
14 |
|
|
if ($group && ($group_info = variable_get_group($group))) {
|
15 |
|
|
$group_info += array('description' => '');
|
16 |
|
|
drupal_set_title($group_info['title']);
|
17 |
|
|
$list = variable_list_group($group);
|
18 |
|
|
$build['description']['#markup'] = '<h3>' . $group_info['description'] . '</h3>';
|
19 |
|
|
$build['form'] = drupal_get_form('variable_edit_form', array_keys($list), $realm_options);
|
20 |
|
|
return $build;
|
21 |
|
|
}
|
22 |
|
|
else {
|
23 |
|
|
// Groups overview
|
24 |
|
|
$build['groups'] = array(
|
25 |
|
|
'#type' => 'vertical_tabs',
|
26 |
|
|
);
|
27 |
|
|
foreach (variable_get_group() as $group => $info) {
|
28 |
|
|
if ($group_variables = variable_list_group($group)) {
|
29 |
|
|
$build['groups'][$group] = array(
|
30 |
|
|
'#type' => 'fieldset',
|
31 |
|
|
'#title' => $info['title'],
|
32 |
|
|
'#collapsible' => TRUE, '#collapsed' => TRUE,
|
33 |
|
|
'#description' => (!empty($info['description']) ? $info['description'] . ' ' : '') . l(t('Edit group variables'), 'admin/config/system/variable/group/' . $group),
|
34 |
|
|
);
|
35 |
|
|
$build['groups'][$group]['list'] = variable_admin_group_list($group_variables, $realm_options);
|
36 |
|
|
}
|
37 |
|
|
}
|
38 |
|
|
return $build;
|
39 |
|
|
}
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
/**
|
43 |
|
|
* Build list of variables for group
|
44 |
|
|
*
|
45 |
|
|
* @return Renderable array
|
46 |
|
|
*/
|
47 |
|
|
function variable_admin_group_list($variables, $options = array()) {
|
48 |
|
|
$list = array();
|
49 |
|
|
foreach ($variables as $name => $variable) {
|
50 |
|
|
$type = variable_get_type($variable['type']);
|
51 |
|
|
$list[$name] = array(
|
52 |
|
|
'#type' => 'item',
|
53 |
|
|
'#title' => l($variable['title'], 'admin/config/system/variable/edit/' . $name) . ' (' . $type['title'] . ')',
|
54 |
|
|
'#markup' => variable_format_value($variable, $options), //
|
55 |
|
|
'#description' => isset($variable['description']) ? $variable['description'] : '',
|
56 |
|
|
);
|
57 |
|
|
}
|
58 |
|
|
return $list;
|
59 |
|
|
return array(
|
60 |
|
|
'#theme' => 'table',
|
61 |
|
|
'#rows' => $list,
|
62 |
|
|
);
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Variable overview, by group
|
67 |
|
|
*/
|
68 |
|
|
function variable_admin_page_module($name = NULL) {
|
69 |
|
|
variable_include();
|
70 |
|
|
$build['message']['#markup'] = _variable_admin_realm_message();
|
71 |
|
|
$realm_options = _variable_admin_realm_options();
|
72 |
|
|
if ($name && (in_array($name, module_list()))) {
|
73 |
|
|
$modules = system_list('module_enabled');
|
74 |
|
|
$module = $modules[$name];
|
75 |
|
|
drupal_set_title($module->info['name']);
|
76 |
|
|
$list = variable_list_module($name);
|
77 |
|
|
$build['description']['#markup'] = $module->info['description'];
|
78 |
|
|
$build['form'] = drupal_get_form('variable_edit_form', array_keys($list), $realm_options);
|
79 |
|
|
return $build;
|
80 |
|
|
}
|
81 |
|
|
else {
|
82 |
|
|
// Groups overview
|
83 |
|
|
$build['modules'] = array(
|
84 |
|
|
'#type' => 'vertical_tabs',
|
85 |
|
|
|
86 |
|
|
);
|
87 |
|
|
foreach (system_list('module_enabled') as $module) {
|
88 |
|
|
if ($variables = variable_list_module($module->name)) {
|
89 |
|
|
$build['modules'][$module->name] = array(
|
90 |
|
|
'#type' => 'fieldset',
|
91 |
|
|
'#title' => $module->info['name'],
|
92 |
|
|
'#collapsible' => TRUE, '#collapsed' => TRUE,
|
93 |
|
|
'#description' => $module->info['description'] . ' ' . l(t('Edit module variables'), 'admin/config/system/variable/module/' . $module->name),
|
94 |
|
|
'#group' => 'modules',
|
95 |
|
|
);
|
96 |
|
|
$build['modules'][$module->name]['list'] = variable_admin_group_list($variables, $realm_options);
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
return $build;
|
100 |
|
|
}
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
/**
|
104 |
|
|
* Lists available realms.
|
105 |
|
|
*/
|
106 |
|
|
function variable_admin_realm_overview($form, $form_state) {
|
107 |
|
|
$header = array(
|
108 |
|
|
t('Realm name'),
|
109 |
|
|
t('Weight'),
|
110 |
|
|
t('Options'),
|
111 |
|
|
);
|
112 |
|
|
|
113 |
|
|
$realms = array();
|
114 |
|
|
foreach (variable_realm_info() as $realm => $info) {
|
115 |
|
|
$options = array();
|
116 |
|
|
// Add list of configured variables + configuration link
|
117 |
|
|
if (!empty($info['select'])) {
|
118 |
|
|
$options[] = l(t('Configure'), 'admin/config/system/variable/realm/' . $realm . '/configure');
|
119 |
|
|
$options[] = l(t('Edit'), 'admin/config/system/variable/realm/' . $realm . '/edit');
|
120 |
|
|
}
|
121 |
|
|
// Get weight from realm controller.
|
122 |
|
|
$controller = variable_realm_controller($realm);
|
123 |
|
|
$realms[] = array(
|
124 |
|
|
l($info['title'], 'admin/config/system/variable/realm/' . $realm),
|
125 |
|
|
$controller->getDefaultWeight(),
|
126 |
|
|
implode(' | ' , $options)
|
127 |
|
|
);
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
$form['realms'] = array(
|
131 |
|
|
'#theme' => 'table',
|
132 |
|
|
'#header' => $header,
|
133 |
|
|
'#rows' => $realms,
|
134 |
|
|
'#empty' => t('No realms available.'),
|
135 |
|
|
);
|
136 |
|
|
|
137 |
|
|
return $form;
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
/**
|
141 |
|
|
* Lists available realms.
|
142 |
|
|
*/
|
143 |
|
|
function variable_admin_realm_info($realm_name) {
|
144 |
|
|
$controller = variable_realm_controller($realm_name);
|
145 |
|
|
$build['title'] = array(
|
146 |
|
|
'#type' => 'item',
|
147 |
|
|
'#title' => t('Name'),
|
148 |
|
|
'#markup' => $controller->getTitle(),
|
149 |
|
|
);
|
150 |
|
|
$build['keys'] = array(
|
151 |
|
|
'#theme' => 'item_list',
|
152 |
|
|
'#title' => t('Keys'),
|
153 |
|
|
'#items' => $controller->getAllKeys(),
|
154 |
|
|
);
|
155 |
|
|
$build['variables'] = array(
|
156 |
|
|
'#theme' => 'item_list',
|
157 |
|
|
'#title' => t('Variables'),
|
158 |
|
|
'#items' => $controller->getEnabledVariables(),
|
159 |
|
|
);
|
160 |
|
|
if ($controller->getInfo('select')) {
|
161 |
|
|
$build['options'] = array(
|
162 |
|
|
'#theme' => 'item_list',
|
163 |
|
|
'#title' => t('Options'),
|
164 |
|
|
'#items' => array(
|
165 |
|
|
l(t('Configure'), 'admin/config/system/variable/realm/' . $realm_name . '/configure'),
|
166 |
|
|
l(t('Edit'), 'admin/config/system/variable/realm/' . $realm_name . '/edit'),
|
167 |
|
|
),
|
168 |
|
|
);
|
169 |
|
|
}
|
170 |
|
|
return $build;
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
/**
|
174 |
|
|
* Edit variables for realm.
|
175 |
|
|
*/
|
176 |
|
|
function variable_admin_realm_edit($realm_name) {
|
177 |
|
|
module_load_include('form.inc', 'variable_realm');
|
178 |
|
|
$realm_key = variable_realm_form_key_current($realm_name);
|
179 |
|
|
$build['select'] = variable_realm_form_key_selector($realm_name, $realm_key);
|
180 |
|
|
$build['form'] = drupal_get_form('variable_realm_edit_variables_form', $realm_name, $realm_key);
|
181 |
|
|
return $build;
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
/**
|
185 |
|
|
* Message for forms viewing / editing global variables.
|
186 |
|
|
*/
|
187 |
|
|
function _variable_admin_realm_message() {
|
188 |
|
|
if (module_exists('variable_realm')) {
|
189 |
|
|
return '<p>' . t('These are global default variables. To edit variables for a specific realm go to <a href="@variable-realm">Variable Realms</a>', array('@variable-realm' => url('admin/config/system/variable/realm'))) .'</p>';
|
190 |
|
|
}
|
191 |
|
|
else {
|
192 |
|
|
return '';
|
193 |
|
|
}
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
/**
|
197 |
|
|
* Options for forms viewing / editing global variables.
|
198 |
|
|
*/
|
199 |
|
|
function _variable_admin_realm_options() {
|
200 |
|
|
if (module_exists('variable_realm')) {
|
201 |
|
|
$options['realm'] = variable_realm('global', 'default');
|
202 |
|
|
$options['realm_name'] = 'global';
|
203 |
|
|
$options['realm_key'] = 'default';
|
204 |
|
|
return $options;
|
205 |
|
|
}
|
206 |
|
|
else {
|
207 |
|
|
return array();
|
208 |
|
|
}
|
209 |
|
|
} |