3

Flag Module is a very effective module for tagging entities which - apparently - only handles two status: "flagged" and "unflagged", while I need now to know if an entity was even been flagged before. So, 3 status:

  • "never flagged"
  • "flagged"
  • "unflagged"

Which solution have we today in order to see if an entity has ever been flagged?

8
  • I haven't used flag in about a year, but last time I did I'm pretty sure it didn't have functionality like that. You might be able to query the flag_counts table and infer that entities missing from there have never been flagged. But I'm not sure if the module does maintenance on that table, it's a big module – Clive May 11 '16 at 9:39
  • This sounds like a unique use case. I doubt there is anything out there for you. Looks like building a custom module to keeps track in the DB when a flag is flagged maybe the only way. – No Sssweat May 11 '16 at 9:41
  • When you unflag a count=1 record in flag_counts, flag module deletes that record. Having an "update count=0" would have solved that. Good point, @Clive – augusto May 11 '16 at 9:49
  • 1
    Ah right, I hadn't dived that far into it. Flag has a great API to be fair to it, @NoSssweat's suggestion of just creating a DB table in a custom module to track it yourself is a good one; you'd probably only need a single db_merge in a flag insert/update hook to make that happen – Clive May 11 '16 at 9:52
  • mymodule_flag_flag($flag, $content_id, $account, $flagging) { // Do something in response to the flagging. } – No Sssweat May 11 '16 at 10:00
2

IMO there is a solution without custom coding ... Below is a synopsis (to avoid writing a manual ...) of how to get this to work ...

Step 1:

Create an additional flag, let's label it like "Ever flagged with FlagX" (whereas 'FlagX' reflects the flag for which you want to know if the entity was ever flagged).

Step 2:

Use the Rules module to create a rule like so:

  • Rules Event: After entity (=node or user) is flagged with FlagX
  • Rules Action: Flag an entity (= node or user), with parameter the flag "Ever flagged with FlagX"

Here is a sample of such rule (in Rules export format, adapt the machine name of both flags to fit your needs prior to importing it in your own site), for a flag used for flagging an entity of type "user":

{ "rules_set_the_ever_flagged_with_flagx_flag" : {
    "LABEL" : "Set the ever flagged with FlagX flag",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "flag" ],
    "ON" : { "flag_flagged_flagx" : [] },
    "DO" : [
      { "flag_flaguser" : {
          "flag" : "ever_flagged_with_flagx ",
          "user" : [ "flagged-user" ],
          "flagging_user" : [ "flagging-user" ],
          "permission_check" : "1"
        }
      }
    ]
  }
}

Step 3:

"To know if an entity was ever been flagged before" (as in your question), all you need to do now is to check for the entities that have been flagged with the "Ever flagged with FlagX" flag. Obviously, it should be straight forward to use the Views module to create an appropriate list of those entities (like users) for which the "Ever flagged with FlagX" flag is not yet set ... which would then be the actual answer to your question, i.e. the entities (like users) which were "Never flagged with FlagX".

6
  • 2
    Interesting approach – Adrian Cid Almaguer May 11 '16 at 12:27
  • @AdrianCidAlmaguer: merci! Things don't always have to be complicated, right? And Keep It Super Simple solutions are also easy to maintain, upgrade, etc, no? – Pierre.Vriens May 11 '16 at 12:33
  • @Pierre.Vriens plan is cool! Unfortunately, we cannot have that 3rd status in the flag link, though. IMO, the one who's editing a question should not think at actual answer... – augusto May 16 '16 at 11:23
  • @augusto: I don't understand your last comment. I'm not talking about a "3rd status". Instead my answer, in step one, is about an additional flag. Also, I don't understand your"the one who's editing a question should not think at actual answer". So can you try again to better explain your last comment? – Pierre.Vriens May 17 '16 at 6:40
  • @Pierre.Vriens, I need a 3rd status, aside the true/false status already handled by Flag. Also, don't edit questions you can't understand (this sounds rude, while I don't want to ... sorry). Thanks for your time spent on this – augusto May 17 '16 at 11:05
1

Add a term reference field to a taxonomy vocabulary that lists the three options.

By default, the field saves as "not flagged", on flag, rules changes it to "flagged" and on unflag, rules changes it to "unflagged".

Add some conditions so the field isn't changed unnecessarily. I never feel bad about adding fields for site features.

3
  • That's indeed another way to reach your goal ... – Pierre.Vriens Aug 28 '16 at 17:04
  • pierre's answer is more detailed. mind putting some details? – Umair Nov 5 '16 at 10:23
  • It's just a taxonomy field with a default of "not flagged" that gets changed by rules when the node is flagged or unflagged. Event: Flag > Action: Taxonomy term: "flagged". And another.. Event: Unflag > Action: Taxonomy term: "unflagged". The key here is that while we still use the flag module, this extra field shows the difference between "not flagged' (the default on node creation) and "unflagged" in an easy way. – Niall Murphy Nov 5 '16 at 14:40

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.