You are here

public function Oauth2ClientPluginBase::submitConfigurationForm in OAuth2 Client 8.3

Form submission handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides PluginFormInterface::submitConfigurationForm

File

src/Plugin/Oauth2Client/Oauth2ClientPluginBase.php, line 254

Class

Oauth2ClientPluginBase
Base class for Oauth2Client plugins.

Namespace

Drupal\oauth2_client\Plugin\Oauth2Client

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  $configuration = $this
    ->getConfiguration();
  $values = $form_state
    ->getValues();
  $provider = $values['credential_provider'];
  $credentials = $values[$provider];
  array_walk($credentials, function (&$value) {
    $value = trim($value);
  });
  $key = $configuration['uuid'];
  if ($provider == 'key') {
    $key = $credentials['id'];
  }
  $configuration['credentials'] = [
    'credential_provider' => $provider,
    'storage_key' => $key,
  ];
  $this
    ->setConfiguration($configuration);
  if ($provider == 'oauth2_client') {

    // Remove the username and password.
    if (isset($credentials['username'])) {
      unset($credentials['username']);
    }
    if (isset($credentials['password'])) {
      unset($credentials['password']);
    }
    $this->state
      ->set($configuration['uuid'], $credentials);
  }
}