-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhide_submit.module
89 lines (80 loc) · 2.98 KB
/
hide_submit.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
<?php
/**
* @file
* This module blocks users from accidentally submitting a form twice. The
* protection only comes from jQuery and is not server side, so this is only
* effective against accidentaly clicking of the button by users with Javascript
* enabled (which is a very high percent of users).
*/
/**
* Adds the settings.
*
* @return
* TRUE if hide_submit is active.
*/
function hide_submit_add_settings() {
static $hide_submit_settings;
if (!$hide_submit_settings) {
$hide_submit_settings = array('hide_submit' => array(
'hide_submit_status' => variable_get('hide_submit_status', TRUE),
'hide_submit_method' => variable_get('hide_submit_method', 'disable'),
'hide_submit_css' => variable_get('hide_submit_css', 'hide-submit-disable'),
'hide_submit_abtext' => t(variable_get('hide_submit_abtext', '')),
'hide_submit_atext' => t(variable_get('hide_submit_atext', '')),
'hide_submit_hide_css' => variable_get('hide_submit_hide_css', 'hide-submit-processing'),
'hide_submit_hide_text' => t(variable_get('hide_submit_hide_text', 'Processing...')),
'hide_submit_hide_fx' => t(variable_get('hide_submit_hide_fx', FALSE)),
'hide_submit_reset_time' => (int)variable_get('hide_submit_reset_time', 5000),
));
// Allow other modules to modify this behavior.
$altered_hide_submit_settings = module_invoke_all('hide_submit_alter', $hide_submit_settings);
if (!empty($altered_hide_submit_settings)) {
// Overwrite the settings with altered values.
$hide_submit_settings = $altered_hide_submit_settings+$hide_submit_settings;
}
// Add settings.
if ($hide_submit_settings['hide_submit']['hide_submit_status']) {
drupal_add_js($hide_submit_settings, 'setting');
}
}
return $hide_submit_settings['hide_submit']['hide_submit_status'];
}
/**
* Implements hook_form_alter().
*/
function hide_submit_form_alter(&$form, &$form_state, $form_id) {
if (hide_submit_add_settings()) {
// Add javascript.
if (!isset($form['#attached']['js'])) {
$form['#attached']['js'] = array();
}
$form['#attached']['js'][drupal_get_path('module', 'hide_submit') . '/hide_submit.js'] = array(
'type' => 'file',
'weight' => 10,
);
// Add css.
if (!isset($form['#attached']['css'])) {
$form['#attached']['css'] = array();
}
$form['#attached']['css'][drupal_get_path('module', 'hide_submit') . '/hide_submit.css'] = array(
'type' => 'file',
'weight' => 10,
);
}
}
/**
* Implements hook_menu().
*/
function hide_submit_menu() {
$items = array();
$items['admin/config/content/hide-submit'] = array(
'title' => 'Hide submit settings',
'description' => 'Configure the hiding of the form submit button.',
'page callback' => 'drupal_get_form',
'page arguments' => array('hide_submit_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'hide_submit.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
return $items;
}