Sometimes the default messages outputted by Drupal or the contrib modules aren't always what we want and therefore we are tempted to make the necessary changes to suit our needs. This little article is a nice way to override the default new message indication block to something more of your choice. By default, when a user receives a new message, it reads "You have a new message, click here to read it" and if there are multiple messages "You have @count new messages, click here to read them". But let's say I want to make it simpler. The snippet below will show you how its done.

function theme_privatemsg_new_block($count) {
  $text = format_plural($count, 'You have a new message, click here to read it',
                        'You have @count new messages, click here to read them',
                        array('@count' => $count));

  return l($text, 'messages', array('attributes' => array('id' => 'privatemsg-new-link')));
}

Copy the above snippet to your theme's template.tpl.php file and paste it anywhere of your choice (easiest place is at the bottom) and replace the theme_privatemsg_ to the name of yourthemename_privatemsg_ and replace the $count and the @count values to the words of your choice and clear your theme's cache after uploading to your theme's directory. Thanks to Berdir for his support in helping me to get this to work.

Comments

dojorob76’s picture

I have read quite a few posts from people looking for a solution to theming the New Indication block, and including an image or icon.

Here is how I accomplished this for Drupal 7:

I wanted to show a message icon next to the number of messages, and I only wanted to show the number of messages and the word "new" (i.e., "5 new") as opposed to: "You have x new messages. Click here to read them."

So, in my theme's template.php file, I put

function mytheme_privatemsg_new_block($count) {
  $count = $count['count'];
  if ($count == 0) {
    $text = t('0 new');
  }
  else {
    $text = format_plural($count, '1 new',
                        '@count new');
  }
  return l($text, 'messages', array('attributes' => array('id' => 'privatemsg-new-link')));
}

(Where "mytheme" is the name of my theme).

Next, in my CSS file, I themed the 'privatemsg-new-link' as follows:

a#privatemsg-new-link{
    width: auto;
    height: 35px; /*This is the height of the image I am using for the icon*/
    background: url(../../images/user-mail.png); 
    background-repeat: no-repeat;
    background-position: left;
    display: inline-block;
    text-indent: 50px;
    vertical-align: middle;
}

I hope this is helpful for someone, and if this post is in the wrong place, I apologize, and will happily move it to it's proper place if directed.

j0schi’s picture

Hi,

thanks for the code! unfortunately only a part works for me. if there is no new message it wont display any text. It seems as the whole block got´s disabled if there is no new message :(. tat makes it hard to theme this part. is there an other way? maybe with views?

greetings from Berlin
Patrick

stupiddingo’s picture

In the block settings (/admin/structure/block/manage/privatemsg/privatemsg-new/configure) there is a checkbox at the top you can select to force the block to display if there are no messages.

hockey2112’s picture

How can I make the "(@count new)" text display with bold formatting? And is there a way I could add a class if there are new messages so I can have two icons via css... one for new messages and one for no new messages?