-
Notifications
You must be signed in to change notification settings - Fork 0
/
nice_menus.admin.inc
87 lines (80 loc) · 3.58 KB
/
nice_menus.admin.inc
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
<?php
/**
* @file
* Functionality for Nice Menus administration.
*/
/**
* Settings form as implemented by hook_menu.
*/
function nice_menus_admin_settings($form, &$form_state) {
$form['nice_menus_number'] = array(
'#type' => 'textfield',
'#description' => t('The total number of independent Nice menus blocks you want. Enter a number between 0 and 99. If you set this to 0, you will have no blocks created but you can still use the Nice menus theme functions directly in your theme.'),
'#default_value' => config_get('nice_menus.settings', 'nice_menus_number'),
'#size' => 2,
);
$form['nice_menus_custom_css'] = array(
'#type' => 'textfield',
'#title' => t('Path to custom Nice menus CSS file'),
'#description' => t('To override the default Nice menus CSS layout, enter the path to your custom CSS file. It should be a relative path from the root of your Backdrop install (e.g. themes/example/mymenu.css).'),
'#default_value' => config_get('nice_menus.settings', 'nice_menus_custom_css'),
);
$form['nice_menus_js'] = array(
'#type' => 'checkbox',
'#title' => t('Use JavaScript'),
'#description' => t('This will add Superfish jQuery to Nice menus. This is required for Nice menus to work properly in Internet Explorer.'),
'#default_value' => config_get('nice_menus.settings', 'nice_menus_js'),
);
$form['nice_menus_sf_options'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced: Superfish options'),
'#description' => t('You can change the default Superfish options by filling out the desired values here. These only take effect if the Use JavaScript box above is checked.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['nice_menus_sf_options']['nice_menus_sf_delay'] = array(
'#type' => 'textfield',
'#title' => t('Mouse delay'),
'#description' => t('The delay in milliseconds that the mouse can remain outside a submenu without it closing.'),
'#default_value' => config_get('nice_menus.settings', 'nice_menus_sf_delay'),
'#size' => 5,
);
$form['nice_menus_sf_options']['nice_menus_sf_speed'] = array(
'#type' => 'select',
'#title' => t('Animation speed'),
'#multiple' => FALSE,
'#description' => t('Speed of the menu open/close animation.'),
'#options' => array(
'slow' => t('slow'),
'normal' => t('normal'),
'fast' => t('fast'),
),
'#default_value' => config_get('nice_menus.settings', 'nice_menus_sf_speed'),
);
// Custom validation to make sure the user is entering numbers.
$form['#validate'][] = 'nice_menus_settings_validate';
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
}
/**
* Custom validation for the settings form.
*/
function nice_menus_settings_validate($form, &$form_state) {
$number = $form_state['values']['nice_menus_number'];
// Check to make sure it is a number and that is a maximum of 2 digits.
if (!is_numeric($number) || strlen($number) > 2) {
form_set_error('nice_menus_number', t('You must enter a number from 0 to 99.'));
}
}
function nice_menus_admin_settings_submit($form, &$form_state) {
$config = config('nice_menus.settings');
$config->set('nice_menus_number', $form_state['values']['nice_menus_number']);
$config->set('nice_menus_custom_css', $form_state['values']['nice_menus_custom_css']);
$config->set('nice_menus_js', $form_state['values']['nice_menus_js']);
$config->set('nice_menus_sf_delay', $form_state['values']['nice_menus_sf_delay']);
$config->set('nice_menus_sf_speed', $form_state['values']['nice_menus_sf_speed']);
$config->save();
}