You are here

public function OpenIDConnectAccountsForm::submitForm in OpenID Connect / OAuth client 8

Same name and namespace in other branches
  1. 2.x 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 189

Class

OpenIDConnectAccountsForm
Provides the user-specific OpenID Connect settings form.

Namespace

Drupal\openid_connect\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  list($op, $client_name) = explode('__', $form_state
    ->getTriggeringElement()['#name'], 2);
  if ($op === 'disconnect') {
    $this->authmap
      ->deleteAssociation($form_state
      ->get('account')
      ->id(), $client_name);
    $client = $this->pluginManager
      ->getDefinition($client_name);
    $this
      ->messenger()
      ->addMessage($this
      ->t('Account successfully disconnected from @client.', [
      '@client' => $client['label'],
    ]));
    return;
  }
  if ($this->currentUser
    ->id() !== $form_state
    ->get('account')
    ->id()) {
    $this
      ->messenger()
      ->addError($this
      ->t("You cannot connect another user's account."));
    return;
  }
  $this->session
    ->saveDestination();
  $configuration = $this
    ->config('openid_connect.settings.' . $client_name)
    ->get('settings');

  /** @var \Drupal\openid_connect\Plugin\OpenIDConnectClientInterface $client */
  $client = $this->pluginManager
    ->createInstance($client_name, $configuration);
  $scopes = $this->claims
    ->getScopes($client);
  $_SESSION['openid_connect_op'] = $op;
  $_SESSION['openid_connect_connect_uid'] = $this->currentUser
    ->id();
  $response = $client
    ->authorize($scopes, $form_state);
  $form_state
    ->setResponse($response);
}