forked from RESTful-Drupal/restful
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restful.admin.inc
142 lines (121 loc) · 5.97 KB
/
restful.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Menu callback; Admin settings form.
*/
function restful_admin_settings($form_state) {
$form = array();
$form['restful_default_output_formatter'] = array(
'#type' => 'radios',
'#title' => t('Default formatter'),
'#description' => t('Determine the default formatter that would be used.'),
'#options' => array(),
'#default_value' => variable_get('restful_default_output_formatter', 'json'),
'#required' => TRUE,
);
$element = &$form['restful_default_output_formatter'];
foreach (restful_get_formatter_plugins() as $plugin_name => $plugin) {
$element['#options'][$plugin_name] = check_plain($plugin['label']);
// Add description for each formatter.
if (!$plugin['description']) {
continue;
}
$element[$plugin_name]['#description'] = check_plain($plugin['description']);
}
$params = array(
'@api' => variable_get('restful_hook_menu_base_path', 'api'),
);
$form['file_upload'] = array(
'#type' => 'fieldset',
'#title' => t('File upload'),
);
$form['file_upload']['restful_file_upload'] = array(
'#type' => 'checkbox',
'#title' => t('File upload'),
'#description' => t('When enabled a file upload resource will be available.'),
'#default_value' => variable_get('restful_file_upload', FALSE),
);
$form['file_upload']['restful_file_upload_allow_anonymous_user'] = array(
'#type' => 'checkbox',
'#title' => t('Anonymous file upload'),
'#description' => t('When enabled a file upload resource will be available also for anonymous users.'),
'#default_value' => variable_get('restful_file_upload_allow_anonymous_user', FALSE),
'#states' => array(
'visible' => array(
':input[name=restful_file_upload]' => array('checked' => TRUE),
),
),
);
$form['restful_cache'] = array(
'#type' => 'fieldset',
'#title' => t('Cache'),
'#description' => t('Cache options for the different layers of RESTful.'),
'#collapsible' => FALSE,
);
$form['restful_cache']['restful_page_cache'] = array(
'#type' => 'checkbox',
'#title' => t('Page cache'),
'#description' => t('RESTful can leverage page cache, this will boost your performace for anonymous traffic. !link to start caching responses. Status: <strong>@status</strong>. <strong>CAUTION:</strong> If your resources are using authentication providers other than cookie, you will want to turn this off. Otherwise you may get cached anonymous values for your authenticated GET requests.', array(
'!link' => l(t('Enable page cache'), 'admin/config/development/performance'),
'@status' => variable_get('cache', FALSE) ? t('Enabled') : t('Disabled'),
)),
'#disabled' => !variable_get('cache', FALSE),
'#default_value' => variable_get('restful_page_cache', FALSE) && variable_get('cache', FALSE),
);
$form['restful_cache']['restful_render_cache'] = array(
'#type' => 'checkbox',
'#title' => t('Cache results'),
'#description' => t('When enabled any resource that has not explicitly disabled the caching will be cached. Note that the first hit may result with slower response, although the next ones would be significantly faster. This is different from the page cache in the sense that it acts at the row level (a single entity, a single database row, ...), therefore allowing you to assemble non cached pages with the cached bits faster.'),
'#default_value' => variable_get('restful_render_cache', FALSE),
);
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['advanced']['restful_hijack_api_pages'] = array(
'#type' => 'checkbox',
'#title' => t('Hijack API pages'),
'#description' => t('When enabled all URLS under @api will be handled by RESTful module.', $params),
'#default_value' => variable_get('restful_hijack_api_pages', TRUE),
);
$form['advanced']['restful_hook_menu_base_path'] = array(
'#type' => 'textfield',
'#title' => t('API Base path'),
'#description' => t('Determines the base path of all resources.'),
'#default_value' => variable_get('restful_hook_menu_base_path', 'api'),
);
$form['advanced']['restful_enable_user_login_resource'] = array(
'#type' => 'checkbox',
'#title' => t('Login resource'),
'#description' => t('Determines if the default user login resource should be enabled.'),
'#default_value' => variable_get('restful_enable_user_login_resource', TRUE),
);
$form['advanced']['restful_enable_users_resource'] = array(
'#type' => 'checkbox',
'#title' => t('User resource'),
'#description' => t('Determines if the default user resource should be enabled.'),
'#default_value' => variable_get('restful_enable_users_resource', TRUE),
);
$form['advanced']['restful_enable_discovery_resource'] = array(
'#type' => 'checkbox',
'#title' => t('Discovery resource'),
'#description' => t('Enable discovery resource which shows all accessible resources under @api URL.', $params),
'#default_value' => variable_get('restful_enable_discovery_resource', TRUE),
);
$form['advanced']['restful_global_rate_limit'] = array(
'#type' => 'textfield',
'#title' => t('Rate limit - hits'),
'#description' => t('The number of allowed hits. This is global for all roles. 0 means no global rate limit should be applied.'),
'#default_value' => variable_get('restful_global_rate_limit', 0),
'#element_validate' => array('element_validate_integer'),
);
$form['advanced']['restful_global_rate_period'] = array(
'#type' => 'textfield',
'#title' => t('Rate limit - period'),
'#description' => t('The period string compatible with <a href="@url">\DateInterval</a>. After this period the module will restart counting hits.', array('@url' => 'http://php.net/manual/en/dateinterval.createfromdatestring.php')),
'#default_value' => variable_get('restful_global_rate_period', 'P1D'),
'#element_validate' => array('restful_date_time_format_element_validate'),
);
return system_settings_form($form);
}