You are here

function openid_connect_connect_form in OpenID Connect / OAuth client 7

Form builder: Connect an external account to your existing Drupal account.

1 string reference to 'openid_connect_connect_form'
openid_connect_menu in ./openid_connect.module
Implements hook_menu().

File

includes/openid_connect.forms.inc, line 41
Forms for OpenID Connect.

Code

function openid_connect_connect_form($form, &$form_state, $account) {
  form_load_include($form_state, 'inc', 'openid_connect', 'includes/openid_connect.forms');
  $form_state['account'] = $account;
  $clients = openid_connect_get_plugins(TRUE);
  $form['help'] = array(
    '#prefix' => '<p class="description">',
    '#suffix' => '</p>',
  );
  if (empty($clients)) {
    $form['help']['#markup'] = t('No external account providers are available.');
    return $form;
  }
  elseif ($GLOBALS['user']->uid == $account->uid) {
    $form['help']['#markup'] = t('You can connect your account with these external providers.');
  }
  $connected_accounts = openid_connect_get_connected_accounts($account);
  foreach ($clients as $client) {
    $form[$client['name']] = array(
      '#type' => 'fieldset',
      '#title' => t('Provider: @title', array(
        '@title' => $client['title'],
      )),
    );
    $fieldset =& $form[$client['name']];
    $connected = isset($connected_accounts[$client['name']]);
    $fieldset['status'] = array(
      '#type' => 'item',
      '#title' => t('Status'),
      '#markup' => t('Not connected'),
    );
    if ($connected) {
      $fieldset['status']['#markup'] = t('Connected as %sub', array(
        '%sub' => $connected_accounts[$client['name']],
      ));
      $fieldset['openid_connect_client_' . $client['name'] . '_disconnect'] = array(
        '#type' => 'submit',
        '#value' => t('Disconnect from !client_title', array(
          '!client_title' => $client['title'],
        )),
        '#name' => 'disconnect__' . $client['name'],
      );
    }
    else {
      $fieldset['status']['#markup'] = t('Not connected');
      $fieldset['openid_connect_client_' . $client['name'] . '_connect'] = array(
        '#type' => 'submit',
        '#value' => t('Connect with !client_title', array(
          '!client_title' => $client['title'],
        )),
        '#name' => 'connect__' . $client['name'],
        '#access' => $GLOBALS['user']->uid == $account->uid,
      );
    }
  }
  return $form;
}