hi

how can i change drupal status messages ?
like "Your %post has been created" after an "add node" action
it comes from node.module line: 2266

function node_form_submit($form_id, $form_values) {
...
drupal_set_message(t('Your %post has been created.', array('%post' => node_get_types('name', $node))));
...

thanks in advance

Comments

cog.rusty’s picture

The clean but cumbersome method is to enable the locale module, add a new language, call it for example "Custom Language", make it the default, find the strings you want in the locale page and "translate" them.

The quick and dirty method is of course to hack the string you found directly in the module file.

Or do you mean something else?

paulhudson’s picture

Hello,

How would you change this message for only one node type?

Something in the template.tpl file?

Thanks

Paul

mandarmbhagwat78’s picture

xrayman’s picture

Can't access your link:

check http://drupal.org/node/236729

jefftrnr’s picture

I've removed and modified Drupal messages by searching the sessions variable for the string and removing it. Here's my custom function from my template.php file.

function _exclude_message($mymessage, $mytype="status") {
  $flag = false;
  if ($messageArr = drupal_set_message()) {
    foreach($messageArr as $type=>$messages) {
      if ($mytype==$type) {
        foreach($messages as $key=>$message) {
          if ($mymessage==$message) {
            unset($_SESSION['messages'][$type][intval($key)]);
            $flag = true;
          }
        }
      }
      if (count($_SESSION['messages'][$type])==0) unset($_SESSION['messages'][$type]);
    }
  }
  return $flag;
}

Once you have this, you can call it from a theme function that overrides theme_status_messages


function [themeName]_status_messages($display = NULL) {

  _exclude_message("Thank you for applying for an account. Your account is currently pending approval by the site administrator.<br />In the meantime, your password and further instructions have been sent to your e-mail address."); // success status message from user/register form

  if (_exclude_message("Find this message.","error")) drupal_set_message("testing status replace","error");

  return theme_status_messages($display);
}

(where [themeName] is the name of your theme.)

My first example removes the status message set by the user module when a user registers, the second function call replaces the message with a new string.

It may be tricky, though, to remove a string that has dynamic text (like %type, etc.). The best way may be to use preg_match to find it, or exclude all possible variants. Please reply to this post to tell me where this may not be right, but it seems to work for me so far.

reed.richards’s picture

I wanted to modify the message sent by the node module when a node was created using the hook_nodeapi however the node module sets its message after the hook is called so you can't remove it. I tried the script, it works good. I used the strripos php to search for substrings when I have %type and so on.

jday’s picture

could you elaborate on your strripos method, I'd like to change the 'your @type %title has been created' message on just one type of node.

dgautsch’s picture

did you ever figure this out? I'm trying to do the same thing.

JStarcher’s picture

This function is great and works in Drupal 6 as well, however I made a couple small changes. For some reason, and this may be a Drupal 6 specific problem, when key 0 of the array is removed if there are other messages in the array they will not be displayed. This was fixed by resorting the array after removal. I added a line to remove the entire messages array when all messages have been removed to keep the message from displaying a blank box.

Also, I added a search feature so you don't need to match the exact message, this should help with dynamic text as well.

Updated _exclude_message() function:

function _exclude_message($mymessage, $mytype="status", $search=false) {
  $flag = false;
  if ($messageArr = drupal_set_message()) {
    foreach($messageArr as $type=>$messages) {
      if ($mytype==$type) {
        foreach($messages as $key=>$message) {
          if ($search) {
            if (stristr($message, $mymessage)) {
              unset($_SESSION['messages'][$type][intval($key)]);
              $flag = true;
            }
          } else {
            if ($mymessage==$message) {
              unset($_SESSION['messages'][$type][intval($key)]);
              $flag = true;
            }
          } 
        }
      }
      sort($_SESSION['messages'][$type]);
      if (count($_SESSION['messages'][$type])==0) unset($_SESSION['messages'][$type]);
      if (count($_SESSION['messages'])==0) unset($_SESSION['messages']);
    }
  }
  return $flag;
}

Thanks!

dgautsch’s picture

So how would this work for a specific node type and dynamic text?

Junro’s picture

Here a nice little module to custom status messages.

Custom Submit Messages module