function farm_api_oauth_settings_form in farmOS 7
OAuth client configuration form.
1 string reference to 'farm_api_oauth_settings_form'
- farm_api_menu in modules/
farm/ farm_api/ farm_api.module - Implements hook_menu().
File
- modules/
farm/ farm_api/ farm_api.oauth.inc, line 10 - Farm api form for configuring OAuth Clients.
Code
function farm_api_oauth_settings_form($form, &$form_state) {
// Ask modules for oauth client rediect uri.
$clients = module_invoke_all('farm_api_oauth2_client');
if (empty($clients)) {
$form['empty'] = array(
'#type' => 'markup',
'#markup' => 'There are no OAuth Clients available.',
);
return $form;
}
// Create a set of checkboxes for the clients.
$options = array();
foreach ($clients as $key => $client) {
if (!empty($client['label'])) {
$options[$key] = $client['label'];
}
}
// Load the list of enabled clients.
$default_value = array();
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'oauth2_server_client');
$result = $query
->execute();
if (isset($result['oauth2_server_client'])) {
$client_ids = array_keys($result['oauth2_server_client']);
$active_clients = entity_load('oauth2_server_client', $client_ids);
foreach ($active_clients as $client) {
$default_value[] = $client->client_key;
}
}
// Display as a list of checkboxes.
$form['farm_api_enabled_clients'] = array(
'#type' => 'checkboxes',
'#title' => t('Enable or disable OAuth Clients.'),
'#options' => $options,
'#default_value' => $default_value,
);
// Submit.
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save configuration'),
);
// Return the form.
return $form;
}