4

The problem:

Rules events are missing. EVENT 1. user flagged a statuses and EVENT 2. user flagged a fbss_comment. Everything is available, just need to add these events. Status updates are created by statuses module. I want to log both events mentioned above using message module, but I Cannot unless and until this event is created. Conditions and actions are available by default.

Important Note:

Statuses is not compatible with flag 3. It works with flag 2. When you install flag 2, status updates will show "like" button in status updates and status comments. Not only this, but you will also be able to see status updates of users you are following, in your status stream, when flagged with "follow" flag. Moreover, if you see rules conditions and actions, you will find out that "fbss_comment is flagged" and "statuses is flagged" and similarly actions "flag a statuses" and "flag a fbss_comment" are available. I am getting a feeling that the solution might be hidden within the statuses module folder and its submodules. Just need someone who has an eye to see it. Someone said, "Everything is possible with drupal"

What I tried?

Starting with "user flagged a fbss_comment" event, I went to file fbss_comments_rules.rules.inc in the sub-module fbss_comments. Under function fbss_comments_rules_rules_event_info() I pasted,

'fbss_comments_flag' => array(
      'label' => t('User flags a comment on a status'),
      'group' => t('Statuses Comments'),
      'variables' => array(
        'comment' => array(
          'type' => 'fbss_comment',
          'label' => t('The status comment.'),
        ),
      ),
    ),

Then under function fbss_comments_rules_add_action I added,

function fbss_comments_rules_flag_action($cid, $sid, $message, $uid) {
  fbss_comments_flag_comment($cid, $sid, $message, empty($uid) ? $GLOBALS['user']->uid : $uid);
}

Note: I do not know what I was doing. I just did it as a trial and error.

Message type Export

{
  "name" : "scomments_liked",
  "description" : "Status comments liked",
  "argument_keys" : [ "@scomments_liked_user", "!scomments_liked_statuses_url" ],
  "argument" : [],
  "category" : "message_type",
  "data" : {
    "token options" : { "clear" : 0 },
    "purge" : { "override" : 0, "enabled" : 0, "quota" : "", "days" : "" }
  },
  "language" : "",
  "arguments" : null,
  "message_text" : { "und" : [
      {
        "value" : "@scomments_liked_user liked your comment on the \u003Ca href=\u0022!scomments_liked_statuses_url\u0022\u003EStatus Update\u003C\/a\u003E",
        "format" : "plain_text",
        "safe_value" : "@scomments_liked_user liked your comment on the \u003Ca href=\u0022!scomments_liked_statuses_url\u0022\u003EStatus Update\u003C\/a\u003E"
      }
    ]
  },
  "rdf_mapping" : []
}

Rules Export

{ "rules_statuses_comments_flag" : {
    "LABEL" : "Statuses comments flag",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "statuses" ],
    "REQUIRES" : [ "fbss_comments_rules", "rules" ],
    "ON" : { "fbss_comments_flag" : [] },
    "DO" : [
      { "fbss_comments_rules_load_action" : {
          "USING" : { "cid" : [ "comment:cid" ] },
          "PROVIDE" : { "comment_loaded" : { "comment_loaded" : "Loaded status comment" } }
        }
      },
      { "entity_query" : {
          "USING" : {
            "type" : "user",
            "property" : "uid",
            "value" : [ "comment-loaded:uid" ],
            "limit" : "1"
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "entity_create" : {
          "USING" : {
            "type" : "message",
            "param_type" : "scomments_liked",
            "param_user" : [ "entity-fetched:0" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:arguments:scomments-liked-user" ],
          "value" : "[site:current-user]"
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:arguments:scomments-liked-statuses-url" ],
          "value" : "[comment:comment-status-url]"
        }
      }
    ]
  }
}

Rules Export based on Nial Murphy's answer

{ "rules_user_flagged_statuses" : {
    "LABEL" : "User flagged statuses update",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "statuses" ],
    "REQUIRES" : [ "fbss_rules", "rules", "flag" ],
    "ON" : { "flag_flagged_like" : [] },
    "DO" : [
      { "fbss_rules_load_action" : {
          "USING" : { "sid" : [ "flagged-status:sid" ] },
          "PROVIDE" : { "status_loaded" : { "status_loaded" : "Loaded status" } }
        }
      },
      { "entity_query" : {
          "USING" : {
            "type" : "user",
            "property" : "uid",
            "value" : [ "status-loaded:sender" ],
            "limit" : "1"
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "entity_create" : {
          "USING" : {
            "type" : "message",
            "param_type" : "flagged_status",
            "param_user" : [ "entity-fetched:0" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:arguments:statuses-flagged-user" ],
          "value" : "[flagging-user:name]"
        }
      }
    ]
  }
}
8
  • Currently, what flag events are available? can you post a screenshot?
    – No Sssweat
    Commented Dec 6, 2016 at 1:57
  • see comments below
    – Umair
    Commented Dec 6, 2016 at 17:27
  • Added a rules export to my question based on Niall Murphy's answer
    – Umair
    Commented Dec 8, 2016 at 13:17
  • Hey Umair, I tried to import your (1st) rule, but it fails with an error like so: "Integrity check for the imported configuration failed. Error message: Data selector <em class="placeholder">comment:cid</em> for parameter <em class="placeholder">cid</em> is invalid..". Any idea why? And how I can resolve that import error? Commented Dec 15, 2016 at 19:36
  • @Pierre.Vriens I do not know why. Are you using the niall's version of statuses or the original version? I was having this problem when I installed niall's ver to my existing site. This is what it is showing on that site's rules page. Unknown event "fbss_comments_flag" "Error: Data selector comment:cid for parameter cid is invalid". I guess this is because the niall's ver does not work with the statuses comments. That rule was generated with the original statuses and flag 2. See above "What I tried" section of the question.
    – Umair
    Commented Dec 16, 2016 at 5:02

2 Answers 2

3

Preface - start

This answer assumes you're using the current version of Flag, i.e. 7.x.-3.x. Though a comment below this answer states:

Statuses is not compatible with flag 3. It works with flag 2. When you install flag 2, status updates will show "like" button in status updates and status comments. Not only this, but you will also be able to see status updates of users you are following, in your status stream, when flagged with "follow" flag.

Preface - stop



I'm afraid there is no way to create either of those Rules Events (as in your question):

  • a status update is flagged.
  • a status comment is flagged.

At least not if you're using version 7.x.-3.x. of Flag. Read on to understand why ...

Use the Rules UI to have a look at the available Rules Events, located within the Flag group of events. The number of entries you will find there will vary, but each of them is similar to something like this:

A thing-ie has been flagged, under "something".

Some more details:

  • thing-ie refers to a Drupal entity, like node, user, group, message.
  • something refers to the title of the flag, which you specify when you define (create or edit) your flag in administration.

But when you add a new flag, using /admin/structure/flags/add, the very first thing you are enforced to do is "Select the type of flag to create" (which will become your thing-ie). And the possible options you can select are all entities, such as node, user, group, message, comment, etc. However, something that contains "status" cannot be selected, simply because it's missing in that list (and it is missing, because the Statuses module does NOT create entities).

If however, you'd select "comment" in that list (which sounds close to "status comment", worth trying), then in the next step (at admin/structure/flags/add/comment), you get another list within Bundles, where you can select the bundles that such flag may be used for. The available options in that list are like "ABC comments", whereas "ABC" corresponds to each of your content types. So this won't work either (there is nothing related to "Statuses" that can be selected).

What is above should not be a surprise, simply because of what's mentioned on the Flag's project page (I added the bold markup here):

... Using this module, the site administrator can provide any number of flags for nodes, comments, users, and any other type of entity.

Again, the Statuses module does NOT create entities, and therefor there is no way to come up with something like:

A Status (= thing-ie) has been flagged, under "Some status related title" (= something).

So for all reasons mentioned above, I think you're asking the wrong question:

  • You won't be able to use the Flag module to flag a Status.
  • Try to think of anything else related to the Statuses module that you can use for creating some custom Rules Events that you can use to create a log about something that happened related to Status updates or Status comments.

Maybe this helps you somehow: there are 4 Rules Events available for Statuses and 3 Rules Events for Status Comments. Try to use any of those Rules Events, to do what you'd want to do as extra Rules Actions, similar to what you have in mind if there was an answer to your question.

Sorry, but I'm afraid this is as good as it gets.

5
  • Statuses is not compatible with flag 3. It works with flag 2. When you install flag 2, status updates will show "like" button in status updates and status comments. Not only this, but you will also be able to see status updates of users you are following, in your status stream, when flagged with "follow" flag.
    – Umair
    Commented Nov 25, 2016 at 18:40
  • Moreover, if you see rules conditions and actions, you will find out that "fbss_comment is flagged" and "statuses is flagged" and similarly actions "flag a statuses" and "flag a fbss_comment" are available. I am getting a feeling that the solution might be hidden within the statuses module folder and its submodules. Just need someone who has an eye to see it.
    – Umair
    Commented Nov 25, 2016 at 18:50
  • the rules events I am looking for, are available when I go to "Triggers" module settings, but there are not many actions to choose from. Any idea?
    – Umair
    Commented Dec 3, 2016 at 16:55
  • started a bounty
    – Umair
    Commented Dec 4, 2016 at 16:01
  • @Pierre.Vriens Umair may be interested in a file I've uploaded to Google Drive. His mind may be put at ease if you vouch for me. I can remove all mentions of you and the file afterwards. Commented Dec 5, 2016 at 4:05
3
+50

Umair, have you looked at the patches in drupal.org/node/1787930 and drupal.org/node/1311468 and maybe some others ? I got flag 3 working with the status + rules, but not the comments. It could be possible but I didn't want the comments flaggable so I didn't spend any time trying.

For some reason, I can't recreate the order of patches that got me my working module, here it is to download. It lets me create a new flag type for Status which integrates with Rules and then Message. I just tested it on a clean install and when a status was liked, the action fired.

While I wouldn't particulary trust someone to give me a module of Google Drive, Pierre.Vriens can probably vouch for me not being a bad person and if you do wish to use it in production after testing, I'd encourage you to find the combination / order of patches that results in a 45kb statuses.module file and then work from there. From looking at the .info file, I seem to have to started with the Dev release.

Side-note: You should look at the example files included with the Message module. I have some extremely complex Message scenarios where Rules wasn't good enough and it would be good for you to be aware of the added possibilities.

17
  • 2
    Wow, sharing an entire module, that is really nice Niall! I have not looked at it in detail, but as per your various answers I've seen in the past, I would definitely give it a try as you described here. BTW, no need for any Mentions (or similar). And of course +1 Commented Dec 5, 2016 at 6:01
  • 1
    If pierre trusts you then I trust you. In short, I simply have to install your module and it will solve my problem. right? Of course as you have mentioned above that it will not work on comments. Its ok. I did not understand the 3rd paragraph of your answer.
    – Umair
    Commented Dec 5, 2016 at 11:46
  • Yep. It's just a slightly changed Statuses module. Just enable it and any of its sub-modules that look like they'd be needed and clear the cache. Then, create a new flag for "status" and the default setting will add the flag to /statuses/all. I'm sure you can add it elsewhere no problem. Then create your rule to create the message. Hopefully, it will work as it did for me. The third paragraph was just about re-creating the module as it is now by going through the patches but it's not necessary. Commented Dec 5, 2016 at 13:07
  • 1
    Ha Pierre, it was to perfect for the question to not share the patched module. I had the exact same problem as Umair around six months ago and it felt hopeless trying to get it to work! Commented Dec 5, 2016 at 13:36
  • So everything else will work as it does? for example the "follow" flag.
    – Umair
    Commented Dec 5, 2016 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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