Skip to content
Snippets Groups Projects
Commit be2e196e authored by Kris Booghmans's avatar Kris Booghmans
Browse files

Issue #3452393: Disable username changes

parent 0a140685
Branches
Tags
1 merge request!11Resolve #3452393 "Disable username changes"
Pipeline #191518 passed with warnings
......@@ -103,6 +103,11 @@ function simple_account_policy_form_user_form_alter(&$form, FormStateInterface $
/** @var \Drupal\simple_account_policy\AccountPolicyInterface $accountPolicy */
$accountPolicy = \Drupal::service('simple_account_policy');
$user_prevent_changes = ($accountPolicy->getConfiguration()->get('username_prevent_changes') ?? FALSE);
if ($accountPolicy->applyPolicy($currentUser) && $user_prevent_changes) {
$form['account']['name']['#disabled'] = TRUE;
}
// We need user input here, since fields are not in values (yet).
$input = $form_state->getUserInput();
$data = [
......@@ -112,10 +117,6 @@ function simple_account_policy_form_user_form_alter(&$form, FormStateInterface $
$errors = empty($pass) ? [] : $accountPolicy->validate($currentUser, $data);
$policy = $accountPolicy->policy($currentUser, $errors);
if ($accountPolicy->getConfiguration()->get('username_prevent_changes') ?? FALSE) {
$form['account']['name']['#disabled'] = TRUE;
}
if (!empty($policy['mail'])) {
$form['account']['mail']['#description'] = $policy['mail'];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment