You are here

function oauth_common_edit_form_context_submit in OAuth 1.0 7.4

Same name and namespace in other branches
  1. 6.3 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 462

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) {
    $auth_options[$key] = empty($value) ? null : $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();
  foreach ($values['authorization_levels'] as $key => $level) {
    if (is_numeric($key) && !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/config/services/oauth';
}