Skip to content

Commit

Permalink
Re-order the user edit form, clarifying password management. DDFHER-149
Browse files Browse the repository at this point in the history
  • Loading branch information
rasben committed Nov 28, 2024
1 parent af401ce commit 82c3d74
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ parameters:
- '#Function .*_theme_suggestions_.*\(\) has parameter .* with no value type specified in iterable type array\.#'
# Drupal hook_page_attachments functions uses page array which we cannot provide more detailed typing of.
- '#Function .*_page_attachments\(\) has parameter \$page with no value type specified in iterable type array\.#'
# Drupal hook_module_implements_alter functions uses implementations array which we cannot provide more detailed typing of.
- '#Function .*_module_implements_alter\(\) has parameter \$implementations with no value type specified in iterable type array\.#'
# Drupal hook_requirements() implementation returns array which we cannot provide more detailed typing of.
- '#Function .*_requirements\(\) return type has no value type specified in iterable type array\.#'
# Drupal hook_schema() implementation returns array which we cannot provide more detailed typing of.
Expand Down
31 changes: 31 additions & 0 deletions web/modules/custom/dpl_admin/dpl_admin.module
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,35 @@ function _dpl_admin_form_alter_node_page(array &$form, FormStateInterface $form_
$form['field_hero_title']['#states']['invisible'] = $inactive_state;
$form['field_subtitle']['#states']['invisible'] = $inactive_state;
}
}

/**
* Implements hook_form_FORM_ID_alter() for the user add/edit form.
*
* Re-ordering the user edit form, to make the password demands clearer.
*
* @param array<mixed> $form
* See the $form in dpl_admin_form_alter().
*/
function _dpl_admin_form_alter_user_form(array &$form, FormStateInterface $form_state, string $form_id): void {
$form['account']['current_pass']['#weight'] = 997;
$form['account']['pass']['#weight'] = 998;
$form['account']['password_policy_status']['#weight'] = 999;
}

/**
* Implements hook_module_implements_alter().
*
* Make sure the dpl_admin form_alter happens last, after any other contrib
* modules. This is necessary for us to alter the password policy position.
*/
function dpl_admin_module_implements_alter(array &$implementations, string $hook): void {
if ($hook == 'form_alter') {
$group = $implementations['dpl_admin'];
unset($implementations['dpl_admin']);
$implementations['dpl_admin'] = $group;
}
}

/**
* Implements hook_form_FORM_ID_alter().
Expand Down Expand Up @@ -263,6 +290,10 @@ function dpl_admin_form_alter(array &$form, FormStateInterface $form_state, stri
if (in_array($form_id, ['node_page_form', 'node_page_edit_form'])) {
_dpl_admin_form_alter_node_page($form, $form_state, $form_id);
}

if (in_array($form_id, ['user_register_form', 'user_form'])) {
_dpl_admin_form_alter_user_form($form, $form_state, $form_id);
}
}

/**
Expand Down

0 comments on commit 82c3d74

Please sign in to comment.