3

When someone edits a node, or a profile content type there is a message set with drupal_set_message() that appears at the top of the page. It can look something like this:

Education 45971 has been updated.

How do I change/modify this message before it is displayed to the user? Is there any hook I can use?

0

3 Answers 3

2

On Drupal 6 you have Status Messages Alter, a port for D7 sits in the issue queue.

Status Messages Alter provides developers with a new hook called "hook_message_alter." This hook enables developers to alter the text that is displayed in status messages before the messages are themed.

1

Using your own code, there are essentially two methods.

  • Add the following code at the bottom of the settings.php file:

    // Drupal 6.
    $conf['locale_custom_strings_en'] = array(
      '@type %title has been updated.' => 'The string you want to use',
    );
    
    // Drupal 7.
    $conf['locale_custom_strings_en'][''] = array(
      '@type %title has been updated.' => 'The string you want to use',
    );
    
  • You can override theme_status_messages(), implementing hook_theme_registry_alter(), and filtering out the messages you don't want. In a module, you use code similar to the following one:

    function mymodule_theme_registry_alter(&$theme_registry) {
      if (isset($theme_registry['status_messages'])) {
        $theme_registry['status_messages']['function'] = 'theme_mymodule_status_messages';
      }
    }
    

    theme_mymodule_status_messages() is the function that the module implements to change the messages that would appear to the user, and that modules add through drupal_set_message().

The difference is that with the first method you change the string before the placeholders are replaced with their arguments, while with the second method the string that is passed to the theme function doesn't contain any placeholders.

1

https://drupal.org/project/csm

Allows users to set custom submit messages for different node types via the Drupal UI. So, rather than being stuck with "Page title has been saved", "Page title has been updated" and "Page title has been deleted" the user can set custom submit messages. In addition to this, CSM allows you to change the title of the node creation page. CSM allows both of these things to be set separately for each language your Drupal site is running in.

Also includes a Drupal 7 version of Status Messages Alter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.