public function OpenIDConnectAccountsForm::submitForm in OpenID Connect / OAuth client 2.x
Same name and namespace in other branches
- 8 src/Form/OpenIDConnectAccountsForm.php \Drupal\openid_connect\Form\OpenIDConnectAccountsForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ OpenIDConnectAccountsForm.php, line 170
Class
- OpenIDConnectAccountsForm
- Provides the user-specific OpenID Connect settings form.
Namespace
Drupal\openid_connect\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this->currentUser
->id() !== $form_state
->get('account')
->id()) {
$this
->messenger()
->addError($this
->t("You cannot connect another user's account."));
return;
}
list($op, $client_name) = explode('__', $form_state
->getTriggeringElement()['#name'], 2);
/** @var \Drupal\openid_connect\OpenIDConnectClientEntityInterface $client */
$client = $this->entityTypeManager
->getStorage('openid_connect_client')
->loadByProperties([
'id' => $client_name,
])[$client_name];
switch ($op) {
case 'disconnect':
$this->authmap
->delete($form_state
->get('account')
->id(), 'openid_connect.' . $client_name);
$this
->messenger()
->addMessage($this
->t('Account successfully disconnected from @client.', [
'@client' => $client
->label(),
]));
break;
case 'connect':
$this->session
->saveDestination();
$plugin = $client
->getPlugin();
$scopes = $this->claims
->getScopes($plugin);
$this->session
->saveOp('connect', $this->currentUser
->id());
$response = $plugin
->authorize($scopes);
$form_state
->setResponse($response);
break;
}
}