Custom password reset url on user menu

Created on 5 December 2023, about 1 year ago
Updated 19 December 2023, 12 months ago

Motivation

Give libraries the ability to set a custom URL for patron password reset in place of the default one. We needed to change the default password reset on the user menu.

Resolution

This patch modifies the template "/web/themes/contrib/intercept_base/templates/lists/item-list.html.twig".

User interface changes

In the admin interface under Configuration > System > Basic site settings, we added two fields to the form; one to change the URL value and one to add a tooltip to the link. This change is within our custom module, and not included in the patch.

First, we created a basic settings file when our module is installed. custom_module.install

$config = \Drupal::configFactory()->getEditable('custom_module.settings');
$config->set('password_reset_url', '/user/password');
$config->set('password_reset_tooltip', '');
$config->save();

Then we used the form hook to modify the site settings form. This is within our custom_module.module.

function custom_module_form_system_site_information_settings_alter(&$form, FormStateInterface $form_state, $form_id)
{
  $form['site_information']['password_reset_url'] = [
    '#type' => 'textfield',
    '#title' => t('Password reset url'),
    '#default_value' => \Drupal::config('custom_module.settings')->get('password_reset_url'),
    '#description' => t('This will set a custom URL for user password reset. The default is /user/password'),
  ];

  $form['site_information']['password_reset_tooltip'] = [
    '#type' => 'textfield',
    '#title' => t('Password Reset Tooltip'),
    '#default_value' => \Drupal::config('custom_module.settings')->get('password_reset_tooltip'),
    '#description' => t('Enter the tooltip text for the field.'),
    '#weight' => 99,
  ];

  $form['#submit'][] = 'custom_module_form_system_site_information_settings_submit';
  $form['#submit'][] = '::submitForm';
}

In our submit function we check whether the reset URL is empty, and then set our values.

function custom_module_form_system_site_information_settings_submit(&$form, &$form_state)
{
  $password_reset_url = $form_state->getValue('password_reset_url');
  $password_reset_tooltip = $form_state->getValue('password_reset_tooltip');

  // set default if field is empty
  if (!$password_reset_url) {
    $password_reset_url = '/user/password';
  }

  // Save the new value of our custom setting.
  \Drupal::configFactory()->getEditable('custom_module.settings')
    ->set('password_reset_url', $password_reset_url)
    ->set('password_reset_tooltip', $password_reset_tooltip)
    ->save();
}
✨ Feature request
Status

Downport

Version

1.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States brewskib

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024