'Modify "The changes have been saved." message - Drupal 9
When modifying and saving account information, drupal shows "The changes have been saved." message and that comes from Drupal core user module. Is there a way to modify this message?
Solution 1:[1]
Since status messages are shown using status-messages theme, you can write a preprocess function to alter them:
/**
* Implements hook_preprocess_HOOK().
*
* @param $variables
*/
function YOUR_MODULE_preprocess_status_messages(&$variables) {
$route = \Drupal::routeMatch()->getRouteName();
// Only handle user edit form
if ($route === 'entity.user.edit_form' && isset($variables['message_list']['status'])) {
$status_messages = $variables['message_list']['status'];
foreach ($status_messages as $delta => $message) {
// Find the message and replace it
if ((string) $message === (string) t('The changes have been saved.')) {
$variables['message_list']['status'][$delta] = t('Your message text');
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kien Nguyen |
