Révision 81b16cc2
Ajouté par Assos Assos il y a plus de 6 ans
drupal7/sites/all/modules/webform_validation/webform_validation.admin.inc | ||
---|---|---|
2 | 2 |
|
3 | 3 |
/** |
4 | 4 |
* @file |
5 |
* Manages validation rules administration UI |
|
5 |
* Manages validation rules administration UI.
|
|
6 | 6 |
*/ |
7 | 7 |
|
8 | 8 |
/** |
9 |
* Menu callback function to show an overview of the existing validation rules, and the option to add a rule |
|
9 |
* Menu callback function to show an overview of the existing validation rules, and the option to add a rule.
|
|
10 | 10 |
*/ |
11 | 11 |
function webform_validation_manage($node) { |
12 | 12 |
$rules = webform_validation_get_webform_rules($node); |
... | ... | |
20 | 20 |
} |
21 | 21 |
|
22 | 22 |
/** |
23 |
* Get the list of rules associated with the webform |
|
23 |
* Get the list of rules associated with the webform.
|
|
24 | 24 |
*/ |
25 | 25 |
function webform_validation_get_webform_rules($node) { |
26 | 26 |
if (in_array($node->type, webform_variable_get('webform_node_types'))) { |
... | ... | |
30 | 30 |
return $rules; |
31 | 31 |
} |
32 | 32 |
|
33 |
|
|
34 | 33 |
/** |
35 |
* Themable function to list and re-order the rules assigned to a webform |
|
34 |
* Themable function to list and re-order the rules assigned to a webform.
|
|
36 | 35 |
*/ |
37 | 36 |
function theme_webform_validation_manage_overview_form($variables) { |
38 | 37 |
$form = $variables['form']; |
39 |
$header = array(t('Rule name'), t('Validator'), t('Components'), t('Weight'), array( |
|
40 |
'data' => t('Operations'), |
|
41 |
'colspan' => 2, |
|
42 |
)); |
|
38 |
$header = array( |
|
39 |
t('Rule name'), |
|
40 |
t('Validator'), |
|
41 |
t('Components'), |
|
42 |
t('Weight'), array( |
|
43 |
'data' => t('Operations'), |
|
44 |
'colspan' => 2, |
|
45 |
), |
|
46 |
); |
|
43 | 47 |
|
44 | 48 |
$rows = array(); |
45 | 49 |
foreach (element_children($form) as $rule) { |
46 | 50 |
$row = array(); |
47 | 51 |
foreach (element_children($form[$rule]) as $item) { |
48 |
//unset the titles of the form elements, since we are displaying them in a table with a header. |
|
52 |
// Unset the titles of the form elements, since we are displaying them in |
|
53 |
// a table with a header. |
|
49 | 54 |
unset($form[$rule][$item]['#title']); |
50 |
//add a class to the weight field
|
|
55 |
// Add a class to the weight field.
|
|
51 | 56 |
$form[$rule]['weight']['#attributes']['class'] = array('ruleid-weight'); |
52 | 57 |
$row[] = array( |
53 | 58 |
'data' => drupal_render($form[$rule][$item]), |
... | ... | |
72 | 77 |
'colspan' => 5, |
73 | 78 |
); |
74 | 79 |
} |
75 |
$output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'webform-validation-overview-form'))); |
|
80 |
$output = theme('table', array( |
|
81 |
'header' => $header, |
|
82 |
'rows' => $rows, |
|
83 |
'attributes' => array( |
|
84 |
'id' => 'webform-validation-overview-form', |
|
85 |
), |
|
86 |
)); |
|
76 | 87 |
$output .= drupal_render_children($form); |
77 | 88 |
if ($drag) { |
78 | 89 |
drupal_add_tabledrag('webform-validation-overview-form', 'order', 'sibling', 'ruleid-weight'); |
... | ... | |
81 | 92 |
} |
82 | 93 |
|
83 | 94 |
/** |
84 |
* Form to list and reorder the rules assigned to a webform |
|
95 |
* Form to list and reorder the rules assigned to a webform.
|
|
85 | 96 |
*/ |
86 | 97 |
function webform_validation_manage_overview_form($form, &$form_state, $rules, $node) { |
87 | 98 |
$form = array(); |
... | ... | |
138 | 149 |
* Submit function for rule overview form. |
139 | 150 |
*/ |
140 | 151 |
function webform_validation_manage_overview_form_submit($form, $form_state) { |
141 |
//Save the rule weights. |
|
152 |
// Save the rule weights.
|
|
142 | 153 |
foreach ($form_state['values'] as $ruleid => $value) { |
143 | 154 |
if (is_numeric($ruleid)) { |
144 | 155 |
$update = db_update('webform_validation_rule') |
145 |
->fields(array( |
|
146 |
'weight' => $value['weight'], |
|
147 |
)) |
|
148 |
->condition('ruleid', $ruleid) |
|
149 |
->execute(); |
|
156 |
->fields(array(
|
|
157 |
'weight' => $value['weight'],
|
|
158 |
))
|
|
159 |
->condition('ruleid', $ruleid)
|
|
160 |
->execute();
|
|
150 | 161 |
} |
151 | 162 |
} |
152 | 163 |
drupal_set_message(t('The order of the validation rules has been saved.')); |
153 | 164 |
} |
154 | 165 |
|
155 | 166 |
/** |
156 |
* Callback function to add or edit a validation rule |
|
167 |
* Callback function to add or edit a validation rule.
|
|
157 | 168 |
*/ |
158 |
function webform_validation_manage_rule($form, $form_state, $node, $action = 'add', $validator, $rule = NULL) {
|
|
169 |
function webform_validation_manage_rule($form, $form_state, $node, $action, $validator, $rule = NULL) { |
|
159 | 170 |
$form = array(); |
160 | 171 |
$rule_validator = webform_validation_get_validator_info($validator); |
161 | 172 |
|
... | ... | |
266 | 277 |
} |
267 | 278 |
|
268 | 279 |
/** |
269 |
* Validation handler to add / edit a rule |
|
280 |
* Validation handler to add / edit a rule.
|
|
270 | 281 |
*/ |
271 | 282 |
function webform_validation_manage_rule_validate($form, &$form_state) { |
272 | 283 |
$values = $form_state['values']; |
... | ... | |
280 | 291 |
$selected_components = count(array_filter($values['rule_components'])); |
281 | 292 |
// Check validator min_components and min_components property when they are equal. |
282 | 293 |
if (isset($rule_validator['min_components']) && isset($rule_validator['max_components']) && $rule_validator['min_components'] === $rule_validator['max_components'] && $selected_components !== $rule_validator['min_components']) { |
283 |
form_set_error('rule_components', format_plural($rule_validator['min_components'], 'You need to select exactly @count component', 'You need to select exactly @count components'));
|
|
294 |
form_set_error('rule_components', format_plural($rule_validator['min_components'], 'You need to select exactly @count component', 'You need to select exactly @count components')); |
|
284 | 295 |
} |
285 |
// check validator min_components property
|
|
296 |
// Check validator min_components property.
|
|
286 | 297 |
elseif (isset($rule_validator['min_components']) && $selected_components < $rule_validator['min_components']) { |
287 |
form_set_error('rule_components', format_plural($rule_validator['min_components'], 'You need to select at least @count component', 'You need to select at least @count components'));
|
|
298 |
form_set_error('rule_components', format_plural($rule_validator['min_components'], 'You need to select at least @count component', 'You need to select at least @count components')); |
|
288 | 299 |
} |
289 |
// check validator max_components property
|
|
300 |
// Check validator max_components property.
|
|
290 | 301 |
elseif (isset($rule_validator['max_components']) && $selected_components > $rule_validator['max_components']) { |
291 |
form_set_error('rule_components', format_plural($rule_validator['max_components'], 'You can select @count component at most', 'You can select @count components at most'));
|
|
302 |
form_set_error('rule_components', format_plural($rule_validator['max_components'], 'You can select @count component at most', 'You can select @count components at most')); |
|
292 | 303 |
} |
293 | 304 |
} |
294 | 305 |
|
295 |
|
|
296 | 306 |
/** |
297 |
* Submit handler to add / edit a rule |
|
307 |
* Submit handler to add / edit a rule.
|
|
298 | 308 |
*/ |
299 | 309 |
function webform_validation_manage_rule_submit($form, &$form_state) { |
300 | 310 |
$values = $form_state['values']; |
... | ... | |
302 | 312 |
} |
303 | 313 |
|
304 | 314 |
/** |
305 |
* Get a list of components for a specific webform, filtered by the validator settings |
|
315 |
* Get a list of components for a specific webform, filtered by the validator settings.
|
|
306 | 316 |
*/ |
307 | 317 |
function webform_validation_get_webform_components($node, $validator) { |
318 |
form_load_include($form_state, 'inc', 'webform', 'includes/webform.components'); |
|
319 |
|
|
308 | 320 |
$ret = array(); |
309 | 321 |
$components = $node->webform['components']; |
310 | 322 |
if ($components) { |
... | ... | |
320 | 332 |
} |
321 | 333 |
|
322 | 334 |
/** |
323 |
* Confirmation form to delete a rule |
|
335 |
* Confirmation form to delete a rule.
|
|
324 | 336 |
*/ |
325 | 337 |
function webform_validation_delete_rule($form, &$form_state, $rule) { |
326 | 338 |
if (isset($rule['ruleid'])) { |
... | ... | |
330 | 342 |
); |
331 | 343 |
} |
332 | 344 |
|
333 |
return confirm_form($form, |
|
334 |
t('Are you sure you want to delete the rule %name?', array('%name' => $rule['rulename'])), |
|
335 |
isset($_GET['destination']) ? $_GET['destination'] : $_GET['q'], |
|
336 |
t('This action cannot be undone.'), |
|
337 |
t('Delete'), |
|
338 |
t('Cancel') |
|
345 |
return confirm_form($form, t('Are you sure you want to delete the rule %name?', array('%name' => $rule['rulename'])), isset($_GET['destination']) ? $_GET['destination'] : $_GET['q'], t('This action cannot be undone.'), t('Delete'), t('Cancel') |
|
339 | 346 |
); |
340 | 347 |
} |
341 | 348 |
|
342 | 349 |
/** |
343 |
* Submit handler to delete a rule |
|
350 |
* Submit handler to delete a rule.
|
|
344 | 351 |
*/ |
345 | 352 |
function webform_validation_delete_rule_submit($form, &$form_state) { |
346 | 353 |
$ruleid = $form_state['values']['ruleid']; |
Formats disponibles : Unified diff
Weekly update of contrib modules