I am using Organic Groups, Drupal Commons. If someone posts in group, then all the members should be notified like in Facebook with the number of notifications. Similar to this screenprint:

enter image description here

How can I achieve that ?


  • By Posts I mean a creating new node of Post content type (default) in Organic Group (and commenting part is not required now).
  • I have not implemented any rule for this, can you explain how can I achieve this using rules ?
  • By Posts I mean a creating new node of Post content type (default) in organic group and commenting part is not required now. I have not implemented any rule for this, can you explain how can i achieve this using rules ?
    – FAB
    Commented Feb 27, 2017 at 12:41

2 Answers 2


Below is a blueprint of how you can make this work. To avoid writing a manual as an answer, and to avoid repeating myself, I use some links to other answers (not all of them are mine ...).

Step 1: Get Rules involved

Use the Rules module to capture events about new nodes being created, which belong to some Organic Group. Have a look to either of the answers to "Get organic group name in a rule?", for 2 possible alternatives to "send an eMail" to each member of the group.

With that, all that's left is to replace the Rules Action to "send an eMail" with something that shows the number of notifications (as in your question), as further explained below.

Step 2: Use Messages to create notification entities

Install/enable the Message module also. So that you replace the Rules Action from the previous step to "send an eMail" by a Rules Action to create message "entities" (which is what you get if you use the Message module). And then just use the power of Views to display those messages later on (hang on: in a format like your shiny notification button ...).

Here is a summary of what you'd need:

  1. Define an appropriate Message type, using the Message module. Think of Message types as similar to "Content types", which will be used to create Messages, similar to Nodes.

  2. Enhance your rule with a Rules Action "Create entity" (of type "Message"). Refer to the answer in Which user related token(s) can be used to create a Rule for setting up a message type? for some examples.

  3. Possibly you may also want to add a Rules Action to pass any relevant tokens, via Rules, as Replacement tokens that you can use in your Message type you created with the Message module. Refer to What's the purpose of "Replacement tokens" of a Message type? for more details on this.

  4. Use Views to display the created messages in the format you prefer.

Step 3: Transform the view in a notification icon

The Menu Badges module can be used to add such notifications to any menu item and/or menu tab of your choice. Here are some details about it (from its project page):

Provides a method for adding iOS-style badges to menu items. (see screenshot)

enter image description here

Adding Badges to Menus

Once enabled, go to Administration > Structure > Menus, and click "list links" next to the menu containing the target item. Click "edit" next to the item and select the badge to display with the Display Menu Badge select box.

Adding Badges to Tabs

For adding badges to menu tabs, there is a tab under Administration > Structure > Menus called "Tab Menu Badges". Search for the menu router path of the tab you want to alter, then select a badge from the corresponding select box.

Badge Types

The module includes five example badges, and new badges can be created easily with Views. Modules can also supply their own badges with a hook implementation. See the README.txt file for details.

Because of how it integrates with the Views module, you basically reduce the solution for any type of notification to something like this:

  1. Just create an appropriate view of it, create a menu item or menu tab for that view. Obviously, the view created in Step 2 is the view you want to use.
  2. Do a 15 seconds Menu Badges configuration to tell it which menu item/tab you used for it in your view.

Video tutorials:

Step 4: Updating the notification icon

After you completed the above steps, you'll have such shiny notification icon corresponding to the relevant messages. What's left is to implement something to get the icon (ie the counter shown in it) updated, as further explained below.

Option 1 - Make the Messages manage-able

This option allows a user to indicate which messages have been read already, and which ones are new (= unread). For that, just perform the steps explained in "How to allow users to manage their own Message Stack messages?", which can be summarized like so:

  1. Create a flag (using the Flag module).
  2. Create a view 'Messages by user' (= improved version of the view specifications described above).
  3. Use Rules to flag/unflag messages.
  4. Trigger the Rules Component to mark messages (using the VBO module).
  5. Create notifications about Unread Messages (using the "Menu Badges" module). So that whenever a new message gets created, the user gets a notification in the format of an iOS-like (red) badge with the number of unread messages.

Option 2 - Remove the notification icon after visiting some path

This option will remove the notification icon entirely, after the user visited the dedicated path to display all messages. Refer to the answer to "How to make menu badges count disappear after the page is viewed?" for details about how to do so.

  • Good answer and I do very similar. I've been thinking about enhancing this by possibly using drupal.org/project/rules_link to batch process a second flag field on messages for "Facebook functionality". When the menu item is clicked, the rule fires and all existing messages for the user are automatically flagged so the counter returns to zero. This is how Facebook does it and on my main site, there can be a lot of messages for users to flag. Commented Feb 28, 2017 at 0:54
  • It isn't a priority for me but I may have a look later today. The problem for this approach on Stack Exchange is that it probably requires some jQuery / custom module to make the rules link work seemlessly as a menu item (or whatever people use to display messages). Any thoughts? Commented Feb 28, 2017 at 0:57
  • I think this could also allow a broader range of messages to be displayed in a "wall view" and a narrower range of messages to be displayed for the user in a menu. Just like Facebook. Commented Feb 28, 2017 at 1:04
  • Hey @NiallMurphy , merci for your interesting comments. Please post an extra answer in which you integrate what you described in your comments above. Also note the "Option 2" I added in "Step 4", which IMO is "a" solution for that counter to be returned to zero (as in your first comment). Commented Feb 28, 2017 at 7:02
  • Mine is quite different and I don't use menu badges. My notifications are in a dropdown like FB. i.imgur.com/MRvnPew.png I have it now that when the "44" div is clicked, jQuery steals the href (link+token) from a hidden rules link and I send the $.ajax request myself. That fires the rule in the background while I remove the "44" with jQuery. Commented Feb 28, 2017 at 7:21

FAB, this answer won't be finished for a while but it should let you get closer to FB functionality when it's done when added to Pierre's answer.

Pierre, I'll assume you're comfortable with Rules Link.

It outputs a JS toggle like below which we can hide with CSS.

<div class="rules-link-wrapper rules-link-messages_seen">
  <a href="/seen/1234/_Rr4IZddvsd5kl8VtuNUqFyHPUHQ3LAepC-I1WzujWg" class="rules-link rules-link-js rules-link jquery-once-1-processed" rel="nofollow" title="Seen">Seen</a>
<span class="rules-link-message" style="display: none;">Link executed</span></div>

If our menu item has the class .menu_unread and the badge is .badge_unread, we can do the following to fire our VBO rule.

  $('.menu_unread').click( function () {
              // Get the url from the JS link
              var rules_link_url = $('.rules-link-messages_seen a').attr('href');
              type: 'POST',
              url: rules_link_url,
              dataType: 'json',
              success: function () { 
              // Hide Badge.. Or you could fake set it to zero
                    //So the rule fires once only
                    $(' menu Identifier ').removeClass('menu_unread');

This should also work with flag toggles but won't let us unflag immediately like the default behavior.

Why do this? Fire rules from clicks on any element.

  • Wow, that sounds interesting, merci! Only 1 suggestion to further improve it "some day": don't assume only "I" am interested in learning/reading about this (so replace your 2nd parg about Rules Link with an appropriate explanation, or link to more details on that). Commented Feb 28, 2017 at 8:26
  • I will. My collarbone is still broken so typing big answers is hard. Commented Feb 28, 2017 at 8:28
  • poor Niall ... Get well soon! Commented Feb 28, 2017 at 8:29
  • Thanks. And my left-handed typing is improving dramatically :) Commented Feb 28, 2017 at 8:31
  • Oh yeah Pierre, kind of related in the FB topic. This might interest you. drupal.org/node/2856260 I have Messages pop up using the Toastr library without a page reload. I'll be working at it more in a few weeks. Commented Feb 28, 2017 at 8:44

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