- 方法1:修改settings.php文件
$conf['user.settings']['password_reset_timeout'] = 600;//600秒失效
2.方法2:覆写user_admin_settings表单
<?php
/**
* @file
* Presents a UI element to set the user password reset link timeout.
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_FORM_ID_alter().
*
* Add the password reset link timeout setting on the user settings page.
*
* @see \Drupal\user\AccountSettingsForm
*/
function MODULE_NAME_form_user_admin_settings_alter(&$form, FormStateInterface $form_state) {
$config = \Drupal::configFactory()->getEditable('user.settings');
$form['password_timeout_settings'] = array(
'#type' => 'details',
'#title' => t('Password reset timeout'),
'#open' => TRUE,
'#weight' => 0,
);
$form['password_timeout_settings']['password_reset_timeout'] = [
'#type' => 'number',
'#min' => 1,
'#max' => 31536000,
'#title' => t('Password Reset Timeout'),
'#description' => t('Set the timeout in seconds for one-time login links. The default is 86400 seconds (24 hours).'),
'#default_value' => $config->get('password_reset_timeout', 86400),
];
// Add submit handler to save password_reset_timeout configuration.
$form['#submit'][] = 'MODULE_NAME_user_admin_settings_submit';
}
/**
* Form submission handler for user_admin_settings().
*
* @see MODULE_NAME_form_user_admin_settings_alter()
*/
function MODULE_NAME_user_admin_settings_submit($form, FormStateInterface $form_state) {
$timeout_value = $form_state->getValue('password_reset_timeout');
$config = \Drupal::configFactory()->getEditable('user.settings');
$config->set('password_reset_timeout', $timeout_value)->save();
}