public function RoleForceForm::submitForm in Force Password Change 8
Same name and namespace in other branches
- 2.0.x src/Form/RoleForceForm.php \Drupal\force_password_change\Form\RoleForceForm::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/ RoleForceForm.php, line 117
Class
Namespace
Drupal\force_password_change\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Only execute the code if the checkbox was selected
if ($form_state
->getValue('force_password_change')) {
$role = $form_state
->getValue('role');
// If the role is the authenticated users role, force the change for
// for all users
if ($role
->id() == 'authenticated') {
$this->passwordChangeService
->forceUsersPasswordChange();
}
else {
// Get all UIDS for all members of the role
$uids = $this->passwordChangeService
->getUsersForRole($role
->id());
// If any users are found, force their password change
if (count($uids)) {
$this->passwordChangeService
->forceUsersPasswordChange($uids);
}
}
// Log the force time for the role for statistics sake
$this->passwordChangeService
->updateLastChangeForRoles([
$role
->id(),
]);
// Set a message depending on the site settings
if ($this->configFactory
->get('force_password_change.settings')
->get('check_login_only')) {
drupal_set_message($this
->t('Users in this role will be required to change their password on next login'));
}
else {
drupal_set_message($this
->t('Users in this role will be required to immediately change their password'));
}
}
}