You are here

function oauth_common_edit_form_context in OAuth 1.0 6.3

Same name and namespace in other branches
  1. 7.4 oauth_common.admin.inc \oauth_common_edit_form_context()
  2. 7.3 oauth_common.admin.inc \oauth_common_edit_form_context()

Form to edit the settings of an context.

1 string reference to 'oauth_common_edit_form_context'
oauth_common_edit_context in ./oauth_common.admin.inc
Edit an context.

File

./oauth_common.admin.inc, line 151

Code

function oauth_common_edit_form_context(&$form_state, $context) {
  $form = array(
    '#pre_render' => array(
      '_oauth_common_add_admin_css',
    ),
  );
  $form['cid'] = array(
    '#type' => 'value',
    '#value' => isset($context->cid) ? $context->cid : '',
  );
  $form['context_object'] = array(
    '#type' => 'value',
    '#value' => $context,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#size' => 24,
    '#maxlength' => 32,
    '#default_value' => $context->name,
    '#title' => t('Context name'),
    '#description' => t('A unique name used to identify this preset internally. It must be only be alpha characters and underscores. No spaces, numbers or uppercase characters.'),
    '#required' => TRUE,
  );
  $form['title'] = array(
    '#type' => 'textfield',
    '#size' => 24,
    '#maxlength' => 100,
    '#default_value' => $context->title,
    '#title' => t('Context title'),
    '#required' => TRUE,
  );
  $sign_methods = array(
    'PLAINTEXT' => t('Plaintext'),
  );
  foreach (hash_algos() as $algo) {
    $sign_methods['HMAC-' . strtoupper($algo)] = 'HMAC-' . strtoupper($algo);
  }
  $form['signature_methods'] = array(
    '#type' => 'fieldset',
    '#title' => t('Signature methods'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
    'selected' => array(
      '#type' => 'checkboxes',
      '#title' => t('Supported signature methods'),
      '#options' => $sign_methods,
      '#default_value' => !empty($context->authorization_options['signature_methods']) ? $context->authorization_options['signature_methods'] : array(
        'HMAC-SHA1',
        'HMAC-SHA256',
        'HMAC-SHA384',
        'HMAC-SHA512',
      ),
    ),
  );
  $form['authorization_options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Authorization options'),
    '#tree' => TRUE,
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['authorization_options']['page_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Page title'),
    '#description' => t('The title of the authorization page.'),
    '#size' => 40,
    '#maxlength' => 255,
    '#default_value' => empty($context->authorization_options['page_title']) ? '' : $context->authorization_options['page_title'],
  );
  $form['authorization_options']['message'] = array(
    '#type' => 'textarea',
    '#title' => t('Message'),
    '#description' => t('The message shown to the user when authorizing.'),
    '#default_value' => empty($context->authorization_options['message']) ? '' : $context->authorization_options['message'],
  );
  $form['authorization_options']['warning'] = array(
    '#type' => 'textarea',
    '#title' => t('Warning'),
    '#description' => t('The warning shown to the user when authorizing.'),
    '#default_value' => empty($context->authorization_options['warning']) ? '' : $context->authorization_options['warning'],
  );
  $form['authorization_options']['deny_access_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Deny access title'),
    '#description' => t('The title of deny access link.'),
    '#size' => 40,
    '#maxlength' => 255,
    '#default_value' => empty($context->authorization_options['deny_access_title']) ? '' : $context->authorization_options['deny_access_title'],
  );
  $form['authorization_options']['grant_access_title'] = array(
    '#type' => 'textfield',
    '#title' => t('Grant access title'),
    '#description' => t('The title of grant access button.'),
    '#size' => 40,
    '#maxlength' => 255,
    '#default_value' => empty($context->authorization_options['grant_access_title']) ? '' : $context->authorization_options['grant_access_title'],
  );
  $form['authorization_options']['access_token_lifetime'] = array(
    '#type' => 'textfield',
    '#title' => t('Access token lifetime'),
    '#description' => t('The time, in seconds, for which an access token should be valid, use 0 to never expire access tokens.'),
    '#size' => 10,
    '#maxlength' => 255,
    '#default_value' => empty($context->authorization_options['access_token_lifetime']) ? 0 : $context->authorization_options['access_token_lifetime'],
  );
  $form['authorization_options']['disable_auth_level_selection'] = array(
    '#type' => 'checkbox',
    '#title' => t('Disable authorization level selection'),
    '#description' => t('If this is checked the user won\'t be able to choose the authorization level, and the default authorization level(s) will be used.'),
    '#default_value' => !empty($context->authorization_options['disable_auth_level_selection']),
  );
  $form['authorization_levels'] = array(
    '#type' => 'fieldset',
    '#title' => t('Authorization levels'),
    '#tree' => FALSE,
    'ahah_wrapper' => array(
      '#type' => 'markup',
      '#value' => '<div id="auth-level-wrapper"></div>',
      '#weight' => 9,
    ),
    'add_authorization_level' => array(
      '#type' => 'button',
      '#value' => t('Add authorization level'),
      '#weight' => 10,
      '#ahah' => array(
        'path' => 'admin/settings/oauth/ahah/add-auth-level',
        'wrapper' => 'auth-level-wrapper',
        'method' => 'append',
      ),
    ),
  );
  $i = 0;
  foreach ($context->authorization_levels as $name => $level) {
    $title = !empty($name) ? check_plain($name) : t('New level');
    if ($title == '*') {
      $title = t('Full access');
    }
    $l = oauth_common_edit_form_auth_level($context, $i, $title, $name, $level);
    $form['authorization_levels'][] = $l;
    $i++;
  }
  $form['authorization_level_count'] = array(
    '#type' => 'value',
    '#value' => $i,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}