You are here

public function UserKeyAuthForm::deleteKey in Key auth 8

Submit handler to delete the key.

File

src/Form/UserKeyAuthForm.php, line 169

Class

UserKeyAuthForm
Class UserKeyAuthForm.

Namespace

Drupal\key_auth\Form

Code

public function deleteKey(array &$form, FormStateInterface $form_state) {

  // Delete the key.
  User::load($form['#uid'])
    ->set('api_key', NULL)
    ->save();

  // Alert the user.
  $this
    ->messenger()
    ->addMessage($this
    ->t('Your key has been deleted.'));
}