You are here

function gathercontent_authentication_form in GatherContent 7.3

Callback function for gathercontent administration.

Parameters

array $form: Array with form elements.

array $form_state: Array with form values and state.

Return value

array Array with form elements.

1 string reference to 'gathercontent_authentication_form'
gathercontent_menu in ./gathercontent.module
Implements hook_menu().

File

./gathercontent.authentication.inc, line 23

Code

function gathercontent_authentication_form($form, &$form_state) {
  $form = array();
  $form['gathercontent_username'] = array(
    '#type' => 'textfield',
    '#title' => t('GatherContent User Email Address'),
    '#required' => TRUE,
    '#default_value' => variable_get('gathercontent_username', ''),
    '#description' => t('This is the email address you use to login to
    GatherContent. Your permissions will determine what accounts,
    projects and content is available.'),
  );
  $form['gathercontent_api_key'] = array(
    '#type' => 'textfield',
    '#title' => t('GatherContent API key'),
    '#required' => TRUE,
    '#default_value' => variable_get('gathercontent_api_key', ''),
    '#description' => l(t('Click to find out where you can generate your API Key'), 'https://gathercontent.com/developers/authentication/'),
  );
  if (!$form_state['submitted']) {
    $account = variable_get('gathercontent_account', array());
    if (!empty($account)) {
      $account = array_pop($account);
      $form['current_account'] = array(
        '#prefix' => '<div>',
        '#markup' => t('Current account is <strong>@account</strong>.', array(
          '@account' => $account,
        )),
        '#suffix' => '</div>',
      );
    }
  }
  if ($form_state['submitted']) {
    $account_obj = new Account();
    $data = $account_obj
      ->getAccounts();
    $accounts = array();
    if (!is_null($data)) {
      foreach ($data as $account) {
        $accounts[$account->id] = $account->name;
      }
      $form['account'] = array(
        '#type' => 'select',
        '#options' => $accounts,
        '#title' => t('Select GatherContent Account'),
        '#required' => TRUE,
        '#description' => t('Multiple accounts will be listed if the GatherContent
       user has more than one account. Please select the account you want to
       import and update content from.'),
      );
    }
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => is_null($data) ? t('Verify') : t('Save'),
    );
  }
  else {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => !empty($account) ? t('Change GatherContent Account') : t('Verify'),
    );
  }
  if (!empty($account)) {
    $form['reset'] = array(
      '#type' => 'submit',
      '#value' => t('Reset credentials'),
    );
  }
  return $form;
}