You are here

public function SettingsForm::purgeUsersNowSubmit in Auto Purge Users 8

Same name and namespace in other branches
  1. 8.3 src/Form/SettingsForm.php \Drupal\purge_users\Form\SettingsForm::purgeUsersNowSubmit()
  2. 8.2 src/Form/SettingsForm.php \Drupal\purge_users\Form\SettingsForm::purgeUsersNowSubmit()

Submit handler for mass-account cancellation form.

See also

purge_users_config_form()

File

src/Form/SettingsForm.php, line 337

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\purge_users\Form

Code

public function purgeUsersNowSubmit($form, FormStateInterface $form_state) {

  // Save form submissions.
  $config = $this
    ->config('purge_users.settings');
  $config
    ->set('user_never_lastlogin_value', $form_state
    ->getValue('user_never_lastlogin_value'))
    ->set('user_never_lastlogin_period', $form_state
    ->getValue('user_never_lastlogin_period'))
    ->set('user_lastlogin_value', $form_state
    ->getValue('user_lastlogin_value'))
    ->set('user_lastlogin_period', $form_state
    ->getValue('user_lastlogin_period'))
    ->set('user_inactive_value', $form_state
    ->getValue('user_inactive_value'))
    ->set('user_inactive_period', $form_state
    ->getValue('user_inactive_period'))
    ->set('user_blocked_value', $form_state
    ->getValue('user_blocked_value'))
    ->set('user_blocked_period', $form_state
    ->getValue('user_blocked_period'))
    ->set('enabled_never_loggedin_users', $form_state
    ->getValue('enabled_never_loggedin_users'))
    ->set('enabled_loggedin_users', $form_state
    ->getValue('enabled_loggedin_users'))
    ->set('enabled_inactive_users', $form_state
    ->getValue('enabled_inactive_users'))
    ->set('enabled_blocked_users', $form_state
    ->getValue('enabled_blocked_users'))
    ->set('purge_users_roles', $form_state
    ->getValue('purge_users_roles'))
    ->set('purge_on_cron', $form_state
    ->getValue('purge_on_cron'))
    ->set('inactive_user_notify_text', $form_state
    ->getValue('inactive_user_notify_text'))
    ->set('send_email_notification', $form_state
    ->getValue('send_email_notification'))
    ->set('purge_user_cancel_method', $form_state
    ->getValue('purge_user_cancel_method'))
    ->save();

  // If there is any user to purge.
  $accounts = purge_users_get_user_ids();
  if (!empty($accounts)) {
    $form_state
      ->setRedirect('purge_users.confirm');
    return;
  }
  else {
    drupal_set_message($this
      ->t('No user account found in the system to purge.'));
  }
}