-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgovcms_ckan.admin.inc
More file actions
67 lines (57 loc) · 1.91 KB
/
Copy pathgovcms_ckan.admin.inc
File metadata and controls
67 lines (57 loc) · 1.91 KB
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
<?php
/**
* @file
* Code for the admin pages of the govCMS CKAN module.
*/
/**
* Create settings form for govCMS CKAN.
*
* @return array
* Form API definition.
*/
function govcms_ckan_settings_form() {
$form = array();
$form['govcms_ckan_endpoint_url'] = array(
'#type' => 'textfield',
'#title' => t('Endpoint Url'),
'#description' => t('Specify the endpoint url. Example https://data.gov.au (please note no trailing slash)'),
'#weight' => 0,
'#size' => 100,
'#required' => TRUE,
'#default_value' => variable_get('govcms_ckan_endpoint_url', ''),
);
$form['govcms_ckan_api_key'] = array(
'#type' => 'textfield',
'#title' => t('Api Key'),
'#description' => t('Specify the API key.'),
'#weight' => 1,
'#size' => 100,
'#default_value' => variable_get('govcms_ckan_api_key', ''),
);
$form['#validate'][] = 'govcms_ckan_settings_form_validate';
return system_settings_form($form);
}
/**
* Form validate handler for govCMS CKAN settings form.
*
* @see govcms_ckan_settings_form()
*/
function govcms_ckan_settings_form_validate($form, &$form_state) {
// Get a client instance.
module_load_include('inc', 'govcms_ckan', 'src/GovCmsCkanClient');
$client = new GovCmsCkanClient(
$form_state['values']['govcms_ckan_endpoint_url'],
$form_state['values']['govcms_ckan_api_key']);
// Test the connection using action/package_list resource.
$response_code = $client->testConnection('action/dashboard_activity_list', array('limit' => 1));
// If we don't get a 200 (success), we have problems connecting.
if ($response_code != 200) {
if ($response_code == 403) {
form_set_error('govcms_ckan_api_key', t('API return "Not Authorised" please check your API key.'));
}
else {
form_set_error('govcms_ckan_endpoint_url', t('Could not establish a connection to the endpoint. Error: @code',
array('@code' => $response_code)));
}
}
}