-
Notifications
You must be signed in to change notification settings - Fork 173
/
restful.admin.inc
135 lines (113 loc) · 5.62 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
<?php
use Drupal\restful\Plugin\FormatterPluginManager;
/**
* 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'];
$formatter_manager = FormatterPluginManager::create();
foreach ($formatter_manager->getDefinitions() 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_show_access_denied'] = array(
'#type' => 'checkbox',
'#title' => t('Show access denied records'),
'#description' => t('Check this box to get an HTTP 403 error when requesting entities with access denied. Listing denied entities will remove them from the output and have a flag indicating the access violation. Leave it unchecked to hide access denied records. If you do not care about unpriviledged users knowing that records they do not have access to exist, you can check this box.'),
'#default_value' => variable_get('restful_show_access_denied', FALSE),
);
$form['restful_allowed_origin'] = array(
'#type' => 'textfield',
'#title' => t('Allowed origin'),
'#description' => t('When you make an XHR (AJAX) call to a resource under a different host, most modern browsers will make an initial OPTIONS request to the resource. The response to that can contain the Access-Control-Allow-Origin, if that includes the domain making the request the browser will allow the cross-domain request. The contents of this field will be used in that header. Use <em>*</em> to allow any origin.'),
'#default_value' => variable_get('restful_allowed_origin', ''),
);
$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);
}