-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathartesis_backend.module
188 lines (157 loc) · 5.24 KB
/
artesis_backend.module
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
178
179
180
181
182
183
184
185
186
187
188
<?php
/**
* @file
* Artesis Backend main module file.
*/
/**
* Implements hook_permission().
*/
function artesis_backend_permission() {
$perm = array();
if (module_exists('color')) {
$perm['alter color scheme'] = array(
'title' => t('Change color scheme'),
'description' => t('Enable access for using the color module, altering the site color scheme.'),
);
}
$perm['change alpha settings'] = array(
'title' => t('Change alpha-theme related settings'),
'description' => t('Grant access to change the alpha basetheme settings.'),
);
$perm['change common theme settings'] = array(
'title' => t('Change theme settings'),
'description' => t('Enable, to allow change of common theme settings.')
);
return $perm;
}
/**
* Implements hook_FORM_ID_alter().
*
* Alter the theme settings form.
*/
function artesis_backend_form_system_theme_settings_alter(&$form, &$form_state) {
$common_settings = array(
'theme_settings',
'logo',
'favicon',
);
$change_theme_settings = user_access('change common theme settings');
$change_alpha_settings = user_access('change alpha settings');
$change_color_settings = module_exists('color') && user_access('alter color scheme');
$submit_keys = array();
$validate_keys = array();
// Perform some element removal, so no notices appear on saving settings
// form, when certain sections are not available due to permission
// restrictions.
// Remove common settings form elements and store submit/validate handlers,
// for further removal.
if (!$change_theme_settings) {
foreach ($common_settings as $v) {
unset($form[$v]);
}
$submit_keys[] = array_keys($form['#submit'], 'system_theme_settings_submit');
$validate_keys[] = array_keys($form['#validate'], 'system_theme_settings_validate');
}
// Remove alpha theme settings form elements and store submit/validate
// handlers, for further removal.
if (!$change_alpha_settings) {
unset($form['alpha_settings']);
$submit_keys[] = array_keys($form['#submit'], 'alpha_theme_settings_form_submit');
$validate_keys[] = array_keys($form['#validate'], 'alpha_theme_settings_form_validate');
}
// Remove color module settings form elements and store submit/validate
// handlers, for further removal.
if (!$change_color_settings) {
unset($form['color']);
$submit_keys[] = array_keys($form['#submit'], 'alpha_theme_settings_form_submit');
$validate_keys[] = array_keys($form['#validate'], 'alpha_theme_settings_form_validate');
}
// Remove validate handlers.
foreach ($validate_keys as $v) {
if (isset($v[0]) && isset($form['#validate'][$v[0]])) {
unset($form['#validate'][$v[0]]);
}
}
// Remove submit handlers.
foreach ($submit_keys as $v) {
if (isset($v[0]) && isset($form['#submit'][$v[0]])) {
unset($form['#submit'][$v[0]]);
}
}
}
/**
* Implements hook_TYPE_alter().
*/
function artesis_backend_artesis_ajax_commands_alter(&$ajax_commands) {
$commands[] = artesis_backend_refresh_login();
$commands[] = artesis_backend_refresh_search();
foreach ($commands as $command) {
foreach ($command as $c) {
$ajax_commands[] = $c;
}
}
}
/**
* Refresh the login box via AJAX.
*
* @return Array
* Set of AJAX commands.
*/
function artesis_backend_refresh_login() {
// Get the login block related pieces and update the area via AJAX cmd's.
$commands = array();
$blocks = array();
$blocks['ding_username'] = block_load('ding_user_frontend', 'ding-username');
$blocks['ding_user_loan_number'] = block_load('ding_user_frontend', 'ding-user-loan-number');
$blocks['user_menu'] = block_load('system', 'user-menu');
$commands[] = ajax_command_invoke('.region-user-second-inner', 'html', array(render(_block_get_renderable_array(_block_render_blocks($blocks)))));
$commands[] = ajax_command_artesis_backend_update_login();
return $commands;
}
/**
* Refresh search form via AJAX.
*
* @return Array
* Set of AJAX commands.
*/
function artesis_backend_refresh_search() {
$commands = array();
$search_form = drupal_get_form('search_block_form');
$commands[] = ajax_command_invoke('#search-block-form', 'replaceWith', array(drupal_render($search_form)));
$commands[] = ajax_command_artesis_backend_update_search();
return $commands;
}
/**
* Defines a custom AJAX command to fire necessary logic upon the login
* block.
*
* @return Array
* AJAX-related custom command.
*/
function ajax_command_artesis_backend_update_login() {
drupal_add_js(drupal_get_path('module', 'artesis_backend') . '/js/artesis_backend.scripts.js', 'file');
return array(
'command' => 'artesis_backend_update_login',
);
}
/**
* Defines a custom AJAX command to fire necessary logic upon the login
* block.
*
* @return Array
* AJAX-related custom command.
*/
function ajax_command_artesis_backend_update_search() {
drupal_add_js(drupal_get_path('module', 'artesis_backend') . '/js/artesis_backend.scripts.js', 'file');
return array(
'command' => 'artesis_backend_update_search',
);
}
/**
* Implements hook_menu_alter().
*/
function artesis_backend_menu_alter(&$items) {
if (module_exists('nopremium')) {
$items['admin/config/workflow/nopremium']['access arguments'] = array('access administration pages');
}
}