|
9 | 9 | * Form builder.
|
10 | 10 | */
|
11 | 11 | function queueit_settings_form($form, &$form_state) {
|
12 |
| - // Configuration parameters. |
| 12 | + /* Main configuration */ |
13 | 13 | $form['config'] = array(
|
14 | 14 | '#title' => 'Queue-it Configuration',
|
15 | 15 | '#type' => 'fieldset',
|
16 | 16 | );
|
17 |
| - $form['config']['queueit_event_id'] = array( |
| 17 | + // Implementation type. |
| 18 | + // * Integration - Validate a user via integration config. |
| 19 | + // * Code - Specify the configuration in code without using the Trigger/Action paradigm. |
| 20 | + $form['config']['queueit_mode'] = array( |
| 21 | + '#type' => 'radios', |
| 22 | + '#title' => t('Queue-it mode.'), |
| 23 | + '#options' => [ |
| 24 | + 'integration' => 'Integration config', |
| 25 | + 'code' => 'Configuration in code', |
| 26 | + //'js' => 'JavaScript', // @todo |
| 27 | + ], |
| 28 | + '#description' => t('Select the type of Queue-it implementation.<br>Select Integration Config to load the configuration from the Go Queue-it platform.<br>Select Configuration in code if your application server is not allowed to do external GET requests (this is without using the Trigger/Action paradigm).'), |
| 29 | + '#default_value' => variable_get('queueit_mode', 'code'), |
| 30 | + ); |
| 31 | + $form['config']['queueit_debug'] = array( |
| 32 | + '#type' => 'checkbox', |
| 33 | + '#title' => t('Enable debugging'), |
| 34 | + '#description' => t('Displays Queue-it response on each qualifying page for admin users only.'), |
| 35 | + '#default_value' => variable_get('queueit_debug', FALSE), |
| 36 | + ); |
| 37 | + /* Configuration using code */ |
| 38 | + $form['event_config'] = array( |
| 39 | + '#title' => 'Event config', |
| 40 | + '#description' => t('When configuration in code is selected, you can specify the following parameters without using the Trigger/Action paradigm. Useful when your application server is not allowed to do external GET requests.'), |
| 41 | + '#type' => 'fieldset', |
| 42 | + '#collapsible' => TRUE, |
| 43 | + '#collapsed' => variable_get('queueit_mode', 'code') == 'integration', |
| 44 | + '#disabled' => variable_get('queueit_mode', 'code') == 'integration', |
| 45 | + ); |
| 46 | + $form['event_config']['queueit_event_id'] = array( |
18 | 47 | '#type' => 'textfield',
|
19 | 48 | '#title' => t('Event ID'),
|
20 | 49 | '#description' => t('Specify ID of the queue to use.'),
|
21 | 50 | '#default_value' => variable_get('queueit_event_id'),
|
22 | 51 | );
|
23 |
| - $form['config']['queueit_queue_domain'] = array( |
| 52 | + $form['event_config']['queueit_queue_domain'] = array( |
24 | 53 | '#type' => 'textfield',
|
25 | 54 | '#title' => t('Domain name of the queue - usually in the format [CustomerId].queue-it.net.'),
|
26 | 55 | '#description' => t('Specify ID of the queue to use.'),
|
27 | 56 | '#default_value' => variable_get('queueit_queue_domain'),
|
28 | 57 | );
|
29 |
| - $form['config']['queueit_cookie_validity'] = array( |
| 58 | + $form['event_config']['queueit_cookie_validity'] = array( |
30 | 59 | '#type' => 'textfield',
|
31 | 60 | '#title' => t('Validity of the Queue-it session cookie.'),
|
32 | 61 | '#description' => t('Optional. Validity of the Queue-it session cookie. Default is 10 minutes.'),
|
33 | 62 | '#default_value' => variable_get('queueit_cookie_validity'),
|
34 | 63 | '#element_validate' => ['element_validate_integer_positive'],
|
35 | 64 | );
|
36 |
| - $form['config']['queueit_extend_cookie_validity'] = array( |
| 65 | + $form['event_config']['queueit_extend_cookie_validity'] = array( |
37 | 66 | '#type' => 'checkbox',
|
38 | 67 | '#title' => t('Extended validity of session cookie.'),
|
39 | 68 | '#description' => t('Should the Queue-it session cookie validity time be extended each time the validation runs? By default it is enabled.'),
|
40 | 69 | '#default_value' => variable_get('queueit_extend_cookie_validity', TRUE),
|
41 | 70 | );
|
42 |
| - $form['config']['queueit_layout_name'] = array( |
| 71 | + $form['event_config']['queueit_layout_name'] = array( |
43 | 72 | '#type' => 'textfield',
|
44 | 73 | '#title' => t('Name of the queue ticket layout.'),
|
45 | 74 | '#description' => t('Optional. E.g. "Default layout by Queue-it. Default is to take what is specified on the Event.'),
|
46 | 75 | '#default_value' => variable_get('queueit_layout_name'),
|
47 | 76 | );
|
48 |
| - $form['config']['queueit_culture_of_layout'] = array( |
| 77 | + $form['event_config']['queueit_culture_of_layout'] = array( |
49 | 78 | '#type' => 'textfield',
|
50 | 79 | '#title' => t('Culture of the queue ticket layout.'),
|
51 | 80 | '#description' => t('Culture of the queue ticket layout in the format specified <a href="!url">here</a>.',
|
52 | 81 | [ '!url' => 'https://msdn.microsoft.com/en-us/library/ee825488(v=cs.20).aspx' ]
|
53 | 82 | ),
|
54 | 83 | '#default_value' => variable_get('queueit_culture_of_layout'),
|
| 84 | + ); |
| 85 | + /* Validation parameters */ |
| 86 | + $form['validate'] = array( |
| 87 | + '#title' => 'Validation logic', |
| 88 | + '#type' => 'fieldset', |
55 | 89 | );
|
56 | 90 | // Exclude Queue-it on specific pages.
|
57 |
| - $form['config']['queueit_exclude_pages'] = array( |
| 91 | + $form['validate']['queueit_exclude_pages'] = array( |
58 | 92 | '#type' => 'textarea',
|
59 | 93 | '#title' => t('Exclude Queue-it on specific pages.'),
|
60 |
| - '#default_value' => variable_get('queueit_exclude_pages', "admin\nadmin/*\nsystem/ajax/*"), |
61 |
| - '#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard."), |
| 94 | + '#default_value' => variable_get('queueit_exclude_pages', QUEUEIT_EXCLUDE), |
| 95 | + '#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. It is recommended to exclude resources and AJAX calls."), |
62 | 96 | );
|
63 |
| - // Credentials. |
| 97 | + $form['validate']['queueit_ignore_post'] = array( |
| 98 | + '#type' => 'checkbox', |
| 99 | + '#title' => t('Ignore queue validation for the POST requests.'), |
| 100 | + '#description' => t('Ignores the KnownUser validation for pages sent via HTTP POST request.'), |
| 101 | + '#default_value' => variable_get('queueit_ignore_post', TRUE), |
| 102 | + ); |
| 103 | + $form['validate']['queueit_ignore_cli'] = array( |
| 104 | + '#type' => 'checkbox', |
| 105 | + '#title' => t('Ignore queue validation for the command-line interface.'), |
| 106 | + '#description' => t('Ignores the KnownUser validation when invoked via CLI (such as using drush).'), |
| 107 | + '#default_value' => variable_get('queueit_ignore_cli', TRUE), |
| 108 | + ); |
| 109 | + /* Credentials */ |
64 | 110 | $form['creds'] = array(
|
65 | 111 | '#title' => 'Queue-it Credentials',
|
66 | 112 | '#type' => 'fieldset',
|
@@ -88,3 +134,47 @@ function queueit_settings_form($form, &$form_state) {
|
88 | 134 |
|
89 | 135 | return system_settings_form($form);
|
90 | 136 | }
|
| 137 | + |
| 138 | +/** |
| 139 | + * Form builder. |
| 140 | + */ |
| 141 | +function queueit_settings_form_validate($form, &$form_state) { |
| 142 | + // Manually load the file classes. |
| 143 | + module_load_include('php', 'queueit', 'src/classes/QueueitBase'); |
| 144 | + module_load_include('php', 'queueit', 'src/classes/QueueitKnownUser'); |
| 145 | + // Validate the configuration. |
| 146 | + try { |
| 147 | + $known_user = new QueueitKnownUser; |
| 148 | + if (!$known_user->validateConfig()) { |
| 149 | + drupal_set_message(t('Queue-it configuration is not valid.'), 'warning'); |
| 150 | + } |
| 151 | + switch (variable_get('queueit_mode', 'code')) { |
| 152 | + case 'code': |
| 153 | + $result = $known_user->validateRequestByIntegrationConfig(); |
| 154 | + break; |
| 155 | + case 'integration': |
| 156 | + $config = $known_user->getIntegrationConfig(); |
| 157 | + if (!$config) { |
| 158 | + drupal_set_message( |
| 159 | + t('Cannot fetch the integration configuration from !url.', |
| 160 | + ['!url' => $known_user->getIntegrationConfigPath()]), |
| 161 | + 'warning'); |
| 162 | + } |
| 163 | + elseif (!json_decode($config)) { |
| 164 | + drupal_set_message( |
| 165 | + t('Cannot decode the integration configuration from !url.', |
| 166 | + ['!url' => $known_user->getIntegrationConfigPath()]), |
| 167 | + 'warning'); |
| 168 | + } |
| 169 | + $result = $known_user->resolveRequestByLocalEventConfig(); |
| 170 | + break; |
| 171 | + } |
| 172 | + } |
| 173 | + catch (\Exception $e) { |
| 174 | + drupal_set_message(t('Exception error: ') . $e->getMessage(), 'error'); |
| 175 | + watchdog_exception('queueit', $e); |
| 176 | + } |
| 177 | + if (!empty($result) && $result) { |
| 178 | + drupal_set_message(t('Configuration successfully validated.'), 'status'); |
| 179 | + } |
| 180 | +} |
0 commit comments