You are here

public function BakeryUncrumbleForm::submitForm in Bakery Single Sign-On System 8.2

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/Forms/BakeryUncrumbleForm.php, line 191

Class

BakeryUncrumbleForm
Contribute form.

Namespace

Drupal\bakery\Forms

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $account = $form_state
    ->getValue('bakery_uncrumble_account');
  $form_state
    ->unsetValue('bakery_uncrumble_account');
  $cookie = $this->kitchen
    ->taste(Kitchen::CHOCOLATE_CHIP);
  $this->database
    ->update('users_field_data')
    ->fields([
    'init' => $cookie['init'],
  ])
    ->condition('uid', $account
    ->id(), '=')
    ->execute();
  $logger = $this
    ->logger('bakery');
  $logger
    ->notice('uncrumble changed init field for uid %uid from %oldinit to %newinit', [
    '%oldinit' => $account
      ->get('init')->value,
    '%newinit' => $cookie['init'],
    '%uid' => $account
      ->id(),
  ]);
  $account
    ->setEmail($cookie['mail']);
  $account
    ->save();
  $logger
    ->notice('uncrumble updated name %name_old to %name_new, mail %mail_old to %mail_new on uid %uid.', [
    '%name_old' => $account
      ->getAccountName(),
    '%name_new' => $cookie['name'],
    '%mail_old' => $account
      ->getEmail(),
    '%mail_new' => $cookie['mail'],
    '%uid' => $account
      ->id(),
  ]);
  $this
    ->messenger()
    ->addMessage(t('Your account has been repaired.'));
  $form_state
    ->setRedirect('user.page');
}