You are here

function oauth_common_edit_form_context_submit 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_submit()
  2. 7.3 oauth_common.admin.inc \oauth_common_edit_form_context_submit()

Process submission of the mini panel edit form.

File

./oauth_common.admin.inc, line 496

Code

function oauth_common_edit_form_context_submit($form, &$form_state) {
  $context = $form_state['values']['context_object'];
  $values = $form_state['values'];
  $context->name = $values['name'];
  $context->title = $values['title'];
  $auth_options = array(
    'access_token_lifetime' => 0,
  );
  foreach ($values['authorization_options'] as $key => $value) {
    if (!empty($value)) {
      $auth_options[$key] = $value;
    }
  }
  $context->authorization_options = $auth_options;

  // Collect the names of the selected signature methods.
  $sig_options = array();
  foreach ($values['signature_methods']['selected'] as $name => $selected) {
    if ($selected) {
      $sig_options[] = $name;
    }
  }
  $context->authorization_options['signature_methods'] = $sig_options;

  // Set the auth levels and default levels for the context
  $levels = array();
  $default_levels = array();
  $level_count = $values['authorization_level_count'];
  for ($idx = 0; $idx < $level_count; $idx++) {
    $level = _oauth_common_auth_level_from_values($idx, $values);
    if (!empty($level['name']) && !$level['delete']) {
      $name = $level['name'];
      if ($level['default']) {
        $default_levels[] = $name;
      }
      $levels[$name] = $level;
    }
  }
  $context->authorization_levels = $levels;
  $context->authorization_options['default_authorization_levels'] = $default_levels;
  oauth_common_context_save($context);
  if (empty($context->cid)) {
    drupal_set_message(t('Your new context %title has been saved.', array(
      '%title' => $context->title,
    )));
    $form_state['values']['cid'] = $context->cid;
  }
  else {
    drupal_set_message(t('Your changes have been saved.'));
  }
  $form_state['redirect'] = 'admin/settings/oauth';
}