2

What I'm trying to do is in theory easy : **User** flagged **Article**. But I'm having hard time figuring out how to build a user feed like this with Message and Flag modules.

I looked a little bit at the Message UI to create a message type, but can't seem to find a "Flagging user" token. The only related flag token I've found is Users who flagged the entity with flag flag which prints all users that liked an article like this:

User A, User B, User C flagged Article

What I really need is to print a message for every flag, like this:

  • User A flagged Article
  • User B flagged Article

And finally show everything in a view to the Article author.

Any suggestions?

2

If you'd add the Rules module (on top of the Message and Flag module you're already using), you can get this to work by using the "Replacement tokens" as part of your "Message type" configuration.

If you're not familiar with these Replacement tokens, you can learn about it the answer to What's the purpose of "Replacement tokens" of a Message type? This answer also includes a sample rule which is similar to what you'll need: it makes the value of token flagging-user available to the Message type.

Some more details to resolve this specific question here:

  1. Add a Replacement token in your Message type, and call it (say) @user_who_flagged (or %user_who_flagged if you prefer).
  2. Use that @user_who_flagged (or %user_who_flagged) token anywhere you want in the message you're trying to produce.
  3. Have Rules create your message (of the message type you're using), which you can do like so:

    • Rules Event "Article gets flagged".
    • Rules Action "Create an entity" (corresponding to your Message type, and use a variable like (say) entity_created for that).
  4. Add an appropriate Rules Action to pass the value of the "Replacement token" (which is used in the Message type as detailed above):

    • which looks like entity-created:arguments:user-who-flagged, and
    • in which you pass the value flagging-user (that's the clue to make it work ...).
  5. Should you want to include additional info in your message about the actual Article (like nid, content type, title, author, whatever), then just create an additional Replacement token for each of them, and a similar Rules Action for each of them also.

With the above approach you'll have your messages created with the custom content you want. Those messages are Drupal entities, so creating an appropriate view from it is straight forward.

For anybody not familiar with the (great) Message module yet (which is poorly dcumented ...), here is your chance to get a first impression about it ... Below is an export of "a" message type that you could use to get started (by simply importing it in your own site). It actually works together with the example rule in the related question. This message type has machine name user_following, and uses a replacement token like @following_user (adapt both to fit your needs, eg change @following_user to @user_who_flagged to use what I suggested above):

{
  "name" : "user_following",
  "description" : "User following",
  "argument_keys" : [ "@following_user" ],
  "argument" : [],
  "category" : "message_type",
  "data" : {
    "token options" : { "clear" : 0 },
    "purge" : { "override" : 0, "enabled" : 0, "quota" : "", "days" : "" }
  },
  "language" : "",
  "arguments" : null,
  "message_text" : { "und" : [
      {
        "value" : "@following_user started following [message:user:name]",
        "format" : "plain_text",
        "safe_value" : "\u003Cp\u003E@following_user started following [message:user:name]\u003C\/p\u003E\n"
      }
    ]
  },
  "rdf_mapping" : []
}

Notes:

  • (to avoid confusion) [message:user:name] in the message type sample above is the user to which the message is targeted, not the flagging user!
  • (if you still don't get the clue of all this) using Rules it's possible to make data originating from any module (such as the Flag module) available as tokens to the Message module.
  • 1
    This was the solution and the right approach.. and yes Message is poorly documented for a great module. – khoy Dec 10 '16 at 10:12
  • 1
    I still don't have the required 50pts to comment. After reading the question and the answers seems that those who downvoted the solution don't know much about Message. When i get the 50 pts i'll try to not forget to post a comment there. Merci beaucoup encore. – khoy Dec 10 '16 at 10:34
0

If I understand your question correctly, this is how you need to set things up:

  1. Create message and flag types you want to use.
  2. Create a new rule that will be triggered when "A node/user/whatever has been flagged, under '[your flag]'".
  3. Add action: Create new entity, select message and fill in the details.
  4. To target the "flagging user" just use [site:current-user] token. This is invoked when the flagging action is taking place, meaning that the current user is the one you need.

Hope this helps.

  • I've edited my question, hope you can help me find a solution. – khoy Mar 14 '16 at 15:59
  • @Aram : I don't think the solution in your answer will work ... Have a look at my answer to understand why I think so. The key issue is that you need a mechanism to pass that "flagging user"-token from "Flag" to "Message", which is what you do using those Replacement Tokens within a "Message Type". Get it? – Pierre.Vriens Nov 10 '16 at 20:10

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.