You are here

public function UserIdentityDelete::submitForm in uLogin (advanced version) 8

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/UserIdentityDelete.php, line 135

Class

UserIdentityDelete
User Identity Delete form.

Namespace

Drupal\ulogin\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $build_info = $form_state
    ->getBuildInfo();
  if (!$form_state
    ->isValueEmpty('identity_choice')) {
    $identity = UloginHelper::identityLoadById($form_state
      ->getValue('identity_choice'));
    $data = unserialize($identity['data']);
    $name = UloginHelper::makeUsername($data);

    // Change name.
    $edit = User::load(\Drupal::currentUser()
      ->id());
    $edit
      ->set('name', $name);

    // Change ulogin data used for tokens.
    foreach ($data as $key => $val) {
      \Drupal::service('user.data')
        ->set('ulogin', $edit
        ->id(), $key, $val);
    }
    $edit
      ->save();

    // Change authname in authmap DB table.
    \Drupal::service('externalauth.authmap')
      ->save($edit, 'ulogin', $name);
  }
  $deleted = UloginHelper::identityDeleteById($build_info['args'][0]);
  if ($deleted) {
    drupal_set_message(t('Identity deleted.'));
  }
  $form_state
    ->setRedirect('ulogin.user', [
    'uid' => \Drupal::currentUser()
      ->id(),
  ]);
}