You are here

public function OAuthAddConsumerForm::submitForm in OAuth 1.0 8.2

Same name and namespace in other branches
  1. 8 src/Form/OAuthAddConsumerForm.php \Drupal\oauth\Form\OAuthAddConsumerForm::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/OAuthAddConsumerForm.php, line 91
Contains \Drupal\oauth\Form\OAuthAddConsumerForm.

Class

OAuthAddConsumerForm
Provides a form to add OAuth consumers.

Namespace

Drupal\oauth\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $consumer_key = user_password(32);
  $consumer_secret = user_password(32);
  $key_hash = sha1($consumer_key);
  $uid = $form_state
    ->getValue('uid');
  $consumer = array(
    'consumer_secret' => $consumer_secret,
    'key_hash' => $key_hash,
  );
  $this->user_data
    ->set('oauth', $uid, $consumer_key, $consumer);
  $this
    ->messenger()
    ->addStatus($this
    ->t('Added a new consumer.'));
  Cache::invalidateTags([
    'oauth:' . $uid,
  ]);
  $form_state
    ->setRedirect('oauth.user_consumer', array(
    'user' => $uid,
  ));
}