2

I am trying to send a simple message to each user in a list of particular users (article publishers) on the site, using the Rules module.

More specifically:

  1. Event: After saving new content

  2. Condition: Content is of type: Article

  3. Action: Load a user list with views (using Rules Bonus pack - user list of article publishers)

  4. Action: Loop (above user list)

  5. Loop action: Show a message on the site

But with above configuration:

1) the only user who's getting the message is the current article publisher and

2) the message is displayed x times where x is the number of users in the user's list.

Apparently something is missing and/or the rule has mistakes.

Can anyone help?

  • What is the list of users? Is it role based or something else. – rooby Apr 21 '13 at 8:12
  • Hi. The list is simply all the (active) users that have created an article node within the site. Active users have the role of authenticated user. – Billy Apr 21 '13 at 8:15
3

The loop isn't checking for the current user, so it is showing a message for all the users in the list, like you describe.

You need to check that the current user is in that list.

To do so you really need the http://drupal.org/project/rules_conditional module. It allows you to have conditions in actions.

So your rule would be something like this:

Event: After saving new content
Condition: Content is of type: Article
Action: Load a user list with views (using Rules Bonus pack - user list of article publishers)
Action loop: Loop (above user list)
  Conditional:
    If: Data comparison (Parameter: Data to compare: [site:current-user:uid], Data value: [list-item:uid])
      Action: Show a message on the site

However, if you say that the list of users is any user that has created an article, and this message is being displayed after a user creates an article, then you can be sure the user who just created the article is in the list of users who have created an article :) So just show the message when an article is created. No other checks for users.

  • I just added a note to the bottom of my answer too. – rooby Apr 21 '13 at 8:22
  • sorry not working. i believe that the message is intended only for the current user. i'll try the Message module. – Billy Apr 21 '13 at 19:39
  • Hey @rooby , correct me if I'm wrong, but I think this rule would prevent that the message is "displayed x times" (as in the question). But still it would only be shown to the "current article publisher" only. Or am I missing something? – Pierre.Vriens Aug 16 '16 at 11:25
  • Very true. I must have misread the question. – rooby Aug 16 '16 at 22:01
  • Note that this question doesn't actually answer the original question however it does show how to show a message to the current user from a list without showing them the message multiple times. – rooby Aug 17 '16 at 4:54
1

To my knowledge, Rules Action Show a message on the site is always targeted to the current user (how would you show a message to a user not logged in to your site?). And if this is done within a loop, like "for all users in the users list" (as in your question), then such message will indeed be "displayed x times where x is the number of users in the users list" (as in your question). So I don't think you can get this to work like you're trying to do. So far the bad news ... read on for good news ...

Instead of using the Rules Bonus Pack, and Rules, you could use the Menu Badges module for such notifications, which you can add to any menu item and/or menu tab of your choice. In your case something like "New articles" seems like an appropriate menu item (or menu tab).

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, by using this integration you basically reduce the solution for any type of notification to something like "Just create an appropriate view of it".

However, there is a small caveat: if you really want the actual number (shown in the red circle) to be accurate, make sure you have some field in your view that will actually correspond to the "After saving new content" part of your question (as in your Rules Event). To better explain this: have a look at the "tracker" view (disabled by default), which has the field "Content:Has new content" (or variation: "Content:Has new comments"). This is a perfect field to use if you want to use Menu Badges to get notified whenever there is new content (or variation: new comments).

Video tutorials:

  • 1
    This is the correct answer. An alternative is to send an email to the article publishers instead of showing them a message. – rooby Aug 16 '16 at 22:00
  • Merci @rooby for your feedback on this! However, I think you should undelete your self deleted answer, and maybe add some kind of update to indicate what's not right in it. That might help <15 K users to somehow "learn from mistakes" also, no? – Pierre.Vriens Aug 16 '16 at 22:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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