public function OpenIDConnectAccountsForm::buildForm in OpenID Connect / OAuth client 2.x
Same name and namespace in other branches
- 8 src/Form/OpenIDConnectAccountsForm.php \Drupal\openid_connect\Form\OpenIDConnectAccountsForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ OpenIDConnectAccountsForm.php, line 109
Class
- OpenIDConnectAccountsForm
- Provides the user-specific OpenID Connect settings form.
Namespace
Drupal\openid_connect\FormCode
public function buildForm(array $form, FormStateInterface $form_state, AccountInterface $user = NULL) : array {
$form_state
->set('account', $user);
/** @var \Drupal\openid_connect\OpenIDConnectClientEntityInterface[] $clients */
$clients = $this->entityTypeManager
->getStorage('openid_connect_client')
->loadByProperties([
'status' => TRUE,
]);
$form['help'] = [
'#prefix' => '<p class="description">',
'#suffix' => '</p>',
];
if (empty($clients)) {
$form['help']['#markup'] = $this
->t('No external account providers are available.');
return $form;
}
elseif ($this->currentUser
->id() == $user
->id()) {
$form['help']['#markup'] = $this
->t('You can connect your account with these external providers.');
}
$connected_accounts = $this->authmap
->getAll($user
->id());
foreach ($clients as $client) {
$id = $client
->id();
$label = $client
->label();
$form[$id] = [
'#type' => 'fieldset',
'#title' => $this
->t('Provider: @title', [
'@title' => $label,
]),
];
$fieldset =& $form[$id];
$connected = isset($connected_accounts['openid_connect.' . $id]);
$fieldset['status'] = [
'#type' => 'item',
'#title' => $this
->t('Status'),
];
if ($connected) {
$fieldset['status']['#markup'] = $this
->t('Connected as %sub', [
'%sub' => $connected_accounts['openid_connect.' . $id],
]);
$fieldset['openid_connect_client_' . $id . '_disconnect'] = [
'#type' => 'submit',
'#value' => $this
->t('Disconnect from @client_title', [
'@client_title' => $label,
]),
'#name' => 'disconnect__' . $id,
];
}
else {
$fieldset['status']['#markup'] = $this
->t('Not connected');
$fieldset['openid_connect_client_' . $id . '_connect'] = [
'#type' => 'submit',
'#value' => $this
->t('Connect with @client_title', [
'@client_title' => $label,
]),
'#name' => 'connect__' . $id,
'#access' => $this->currentUser
->id() == $user
->id(),
];
}
}
return $form;
}