This repository was archived by the owner on May 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherus.admin.php
More file actions
115 lines (87 loc) · 2.68 KB
/
erus.admin.php
File metadata and controls
115 lines (87 loc) · 2.68 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
<?php
/**
* @file
* Administrative interface functionality
*/
/**
* List out all plugins and provide an edit link.
*/
function erus_admin_config_administration_erus() {
$output = "";
$plugins = erus_get_erus_plugin_info();
drupal_set_title('ERUS Plugin List');
$header = array('Plugin Name', 'Module', 'Operations');
$rows = array();
foreach ($plugins as $plugin_name => $values) {
$row = array($plugin_name, $values['module'], l('edit', 'admin/config/administration/erus/' . $plugin_name));
$rows[] = $row;
}
$table_element = array(
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' =>t('You have no plugins defined. Something is wrong.'),
);
$output .= drupal_render($table_element);
return $output;
}
/**
* Implements hook_form().
*/
function erus_plugin_configuration_form($node, &$form_state) {
$plugin_name = arg(4);
$plugin = erus_load_erus_plugin(array('plugin' => $plugin_name));
if (!$plugin) {
drupal_set_message('Could not find plugin by that name', 'error');
return false;
}
drupal_set_title($plugin_name . ' ERUS plugin configuration form');
$form = $plugin->get_configuration_form();
if (empty($form)) {
drupal_set_message('No configuration options for this plugin are available.');
return;
}
$form['erus_hidden_plugin_name'] = array(
'#type' => 'hidden',
'#value' => $plugin_name,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
// Add default values from DB
$values = variable_get('erus_' . $plugin_name, array());
// Loop through the values.
foreach ($values as $field_name => $value) {
if (module_exists('encrypt') && $form[$field_name]['#type'] == "password") {
$value = decrypt($value);
}
$form[$field_name]['#default_value'] = $value;
}
return $form;
}
/**
* Submit handler for configuration_form
* @param [type] $form [description]
* @param [type] $form_state [description]
* @return [type] [description]
*/
function erus_plugin_configuration_form_submit($form, $form_state) {
$values = $form_state['values'];
$plugin_name = check_plain($values['erus_hidden_plugin_name']);
unset($values['erus_hidden_plugin_name']);
// Quick sanitize
foreach ($values as $key => $value) {
$values[$key] = check_plain($value);
}
// If the encrypt module is available lets encrypt all password fields.
if (module_exists('encrypt')) {
foreach ($form as $k => $val) {
if ($val['#type'] == "password") {
$values[$k] = encrypt($values[$k]);
}
}
}
variable_set('erus_' . $plugin_name, $values);
drupal_set_message('Configuration Options Saved');
}