function oauth2_server_scope_form in OAuth2 Server 7
Generates the scope editing form.
File
- includes/
oauth2_server.scope_admin.inc, line 156 - Admin UI for scopes.
Code
function oauth2_server_scope_form($form, &$form_state, $scope, $op = 'edit') {
// Make sure the parent server is present in form state.
if (!isset($form_state['server'])) {
$server = oauth2_server_load(arg(4));
if (!$server) {
return $form;
}
$form_state['server'] = $server;
}
// Set the server on new scope entities, since it serves as the bundle.
// Needed by field_attach_form().
if (empty($scope->server)) {
$scope->server = $form_state['server']->name;
}
// entity_form_field_validate() builds a fake entity from
// $form_state['values'], so the bundle needs to be in there.
$form['server'] = array(
'#type' => 'value',
'#value' => $form_state['server']->name,
);
$form['name'] = array(
'#type' => 'machine_name',
'#default_value' => $scope->name,
'#disabled' => entity_has_status('oauth2_server_scope', $scope, ENTITY_IN_CODE),
'#machine_name' => array(
'exists' => 'oauth2_server_scope_exists',
'replace_pattern' => '[^a-z0-9_\\.]+',
),
'#description' => t('A unique machine-readable name for this scope. It must only contain lowercase letters, numbers, and underscores.'),
'#weight' => -2,
);
$form['description'] = array(
'#title' => t('Description'),
'#type' => 'textfield',
'#default_value' => $scope->description,
'#description' => t('Used to describe the scope to the user on the authorization form.'),
'#required' => TRUE,
'#weight' => -1,
);
field_attach_form('oauth2_server_scope', $scope, $form, $form_state);
$is_default = FALSE;
if (!empty($scope->name) && $form_state['server']->settings['default_scope'] == $scope->name) {
$is_default = TRUE;
}
$form['default'] = array(
'#type' => 'checkbox',
'#title' => t('Default'),
'#default_value' => $is_default,
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save scope'),
'#weight' => 40,
);
if ($op != 'add') {
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete scope'),
'#weight' => 45,
'#limit_validation_errors' => array(),
'#submit' => array(
'oauth2_server_scope_form_submit_delete',
),
);
}
return $form;
}