You are here

function oauth_common_form_consumer in OAuth 1.0 7.4

Same name and namespace in other branches
  1. 6.3 oauth_common.consumers.inc \oauth_common_form_consumer()
  2. 7.3 oauth_common.consumers.inc \oauth_common_form_consumer()

The consumer form that is shared by the add and edit page.

2 string references to 'oauth_common_form_consumer'
oauth_common_add_consumer in ./oauth_common.consumers.inc
Menu system callback for the add consumer page.
oauth_common_edit_consumer in ./oauth_common.consumers.inc
Menu system callback for the edit consumer page.

File

./oauth_common.consumers.inc, line 90

Code

function oauth_common_form_consumer($form, &$form_state, $consumer) {
  $form = array();
  $form['consumer_object'] = array(
    '#type' => 'value',
    '#value' => $consumer,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Consumer name'),
    '#required' => TRUE,
    '#default_value' => $consumer->name,
  );
  $form['callback_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Callback url'),
    '#required' => FALSE,
    '#default_value' => $consumer->callback_url,
  );
  if ($consumer->in_database) {
    $contexts = oauth_common_context_list();
    $form['context'] = array(
      '#type' => 'item',
      '#title' => t('Application context'),
      '#markup' => isset($contexts[$consumer->context]) ? $contexts[$consumer->context] : $consumer->context,
    );
  }
  else {
    $allowed_contexts = array();
    foreach (oauth_common_context_list() as $context => $title) {
      if (user_access(sprintf('oauth register consumers in %s', $context))) {
        $allowed_contexts[$context] = $title;
      }
    }
    $form['context'] = array(
      '#type' => 'select',
      '#title' => t('Application context'),
      '#options' => $allowed_contexts,
      '#default_value' => $consumer->context,
    );
  }
  if ($consumer->in_database) {
    $form['key'] = array(
      '#type' => 'item',
      '#title' => t('Key'),
      '#markup' => $consumer->key,
    );
    $form['secret'] = array(
      '#type' => 'item',
      '#prefix' => '<div id="consumer-secret-wrapper">',
      '#title' => t('Secret'),
      '#markup' => substr($consumer->secret, 0, 6) . '...',
    );
    $form['show_secret'] = array(
      '#type' => 'button',
      '#value' => t('Show secret'),
      '#ajax' => array(
        'callback' => 'oauth_common_form_consumer_secret_ajax_callback',
        'wrapper' => 'consumer-secret-wrapper',
      ),
      '#suffix' => '</div>',
    );
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}