Problem/Motivation
Flag 8.x presently does not include Rules support as Rules 8.x was not yet mature enough to begin development. Flag and Rules can do beautiful things together, and is a must for a complete version of the module.
Proposed resolution
Implement Rules support for flagging events, as well as conditions and actions.
Events
#2540032: Port "Flag is flagged" Rules event to Drupal 10+
#2540034: Port "Flag is unflagged" Rules event to 8.x
Conditions
#2540038: Port "Flag threshold" Rules condition to 8.x
#2540040: Port "Flag is flagged" Rules condition to 8.x
Actions
#2470647: Port "Fetch overall flag count" Rules action to 8.x
#2470653: Port "Fetch user flag count" Rules action to 8.x
#2470659: Port "Fetch [entity type] flagged by user" Rules action to 8.x
#2470661: Port "Flag a [entity type]" Rules action to 8.x
#2470665: Port "Unflag a [entity type]" Rules action to 8.x
#2470669: Port "Fetch users who have flagged a [entity type]" Rules action to 8.x
#2470651: Port "Fetch entity flag count" Rules action to 8.x
#2470645: Port "Trim flag" Rules action to 8.x
Remaining tasks
Code the plugins.
User interface changes
None.
API changes
None.
Comments
Comment #1
socketwench commentedThis issue is postponed until event support is added to Rules. See https://www.drupal.org/node/2145343
Comment #2
shabana.navas commentedAm looking to get on it once the above issue is cleared up in Rules.
Comment #3
dasjoWhile events aren't there yet, you can already implement actions & conditions for Rules. You can take a look at the core integrations that have been ported already:
https://github.com/fago/rules
#2269561: [META] Port all conditions to 8.x
#2269577: [META] Port all actions to 8.x
I think it would be great to create sub-tickets for creating some first action & condition integrations for the flag module to have a proof of concept for a first contrib module integrating with Rules 8.x :)
Comment #4
czigor commentedComment #5
czigor commentedComment #6
czigor commentedComment #7
dasjoComment #8
dasjoSetting to active as some actions are already being ported. See their sub-tickets
Comment #9
martin107 commentedtriggering summary update
Comment #10
dasjonote that rules events are now ready for porting as well #2513476: [META] Port all events to 8.x
Comment #11
dasjoComment #12
socketwench commentedWe should start breaking down this meta into solvable issues now.
Comment #13
dasjoI have pushed a few fixes to my flag fork: for example the Action namespace has been renamed to RulesAction within rules:
https://github.com/dasjo/flag/commits/8.x-4.x-rules
Comment #14
dasjoComment #15
Anonymous (not verified) commentedComment #16
Anonymous (not verified) commentedComment #17
Anonymous (not verified) commentedComment #18
Anonymous (not verified) commentedComment #19
emclaughlin commentedQuestion: do all of the Action ones now depend on #2470661: Port "Flag a [entity type]" Rules action to 8.x being approved and merged? It creates a FlagActionBase class that I assume all of the actions would need to use. I'd really like to dive into this.
Comment #20
joachim commentedThat sounds quite likely. The patch on that issue needs review from someone who's familiar with Rules.
Comment #21
dasjo#19 is correct, you would want to use the FlagActionBase from there
Comment #22
tr commentedPatch which implements "Flag is flagged" AND "Flag is unflagged" events, with tests, may be found in #2540032-21: Port "Flag is flagged" Rules event to Drupal 10+
If you're interested in getting Rules functionality into Flag, please review that patch!
I will work on the Conditions after these two Events are committed.
Comment #23
tr commentedAs I stated 1.5 years ago, I am willing to do the work to port the Rules functionality for this module from D7 to D8. This is all predicated on getting the events ported first. Please review #2540032-21: Port "Flag is flagged" Rules event to Drupal 10+ if this is of interest to you.
Comment #24
CraigBertrand commentedHey folks, what is the status on this? I have installed rules and flag and am having issues getting things to work.
I would be happy to test and perhaps do a how-to video from a user perspective as commits are made.
Comment #25
mobius_time commentedHi all, what is the status of this? What does the road forward look like?
I am developing a site which I may have to do in D7 if Flags and Rules don't work nicely together.
I need to create a rule so that when particular flag is set on a comment or a node, I can then take action.
Thanks to the maintainers for all their hard work on this D8 port.
Comment #26
ivnish5 years without any activity. I think we can close it as outdated. Please reopen if needed.
Comment #27
tr commented@ivnish: This has been blocked for years by the previous Flag maintainer, NOT by lack of interest or work by contributors like me and others. Flag was not being maintained, no tests were being run, porting to D9/D10/D11 was not taking place, no patches were being accepted etc.
The initial patches in this issue to get Events put back into Flag were completed long ago. The other issues depend on that being done first. None of the issues were acted on by the maintainer. To make it clear, the Events patch was blocked because the maintainer wanted "someone more familiar with Rules than myself to mark it RTBC". And to make it more clear, I am the Rules maintainer - I would guess that right now there is no one in the world more familiar with Rules than me. If that wasn't good enough for the previous maintainer, then I don't know what is.
For years I and others have repeatedly done work and offered patches, and re-rolled patches, and answered questions, etc. and it became obvious that it was a waste of time to continue doing that UNLESS the maintainer was willing to review and commit all the contributed work. If that situation has changed, then it would be worthwhile to open MRs for all these issues and re-roll the patches and update everything to run in the current version of Drupal.
So please don't just close this, and please don't blame that on contributors not doing anything. We already spent years working on this and trying to keep it up-to-date. If, as the new Flag maintainer, you're willing to accept the work, then I will do the work.
Event integration is not just for Rules - it's for ANYONE who wants to use an event-based programming model. The proposed Events are not Rules-specific, and don't require Rules to be installed. But without them Rules can only interact with Flag through entity CRUD events, which are provided through core Drupal.
If you are willing to put Rules integration back into Flag, just say so and I will do the work, again, starting with the Events, then moving on to the Conditions and the Actions. All with test cases, of course. This Rules integration adds zero overhead - Event objects aren't even created if there are no Event listeners registered, and Plugins (Conditions and Actions) are never loaded unless they're explicitly requested. No sub-modules are needed. And while some of this integration can be provided outside of the Flag module (any contrib module can provide a plugin), without the Flag events none of that can be used effectively. So the Flag events are critical for Rules integration and testing, that's why this whole meta hinges on getting the events in place first.
Comment #28
ivnishI don't see the point in integrating Rules integration into the flag now because:
1) A lot of years Rules was unusable for production (but I see TR in maintainers now :) )
2) There is Rules Flag
3) There is more modern ECA
But... If you will create good MR with tests I see no reason not to accept them
Comment #29
tr commented1) Not true. Rules has always been working and usable for production. If you mean there has only been alpha and beta releases for most of that time, that's true, but Flag is still beta after all these years too you know ... In the case of Rules, that meant that the D7 features hadn't been ported to D8/D9 yet. In the case of Flag, the features it had in D7 (which includes Rules support) *still* haven't been ported.
These days, in Drupal, nobody uses alpha or beta anymore - everybody makes a "stable" fixed-point release. But it's all semantics. Don't let yourself be fooled by names - a rose by any other name would smell as sweet. That's as true today as it was 450 years ago. I console myself with the knowledge that at least Rules was honest in advertising, but these days no one wants honesty ... if it's fixed-point they'll use it, if it's alpha or beta or -dev they won't. So most modules lie.
2) Nothing inherently wrong with Rules Flag, but it isn't being maintained and there is only so much that a contributed module can do as far as the integration goes. Otherwise all of this could be put into Rules proper. To get deep integration with Flag, you have to add the plugins to Flag. Now that Plugins are part of core, the whole idea of having to install and enable another module for integration is really pretty antiquated - that used to be done only for dependency purposes, but now we can do all that with Plugins with no overhead cost.
3) "more modern" ? The whole idea of 4GL (so-called "fourth-generation programming languages) which provide a complicated UI to avoid actually writing code dates back to the 80's. It was a big topic in the 90's, and with a few notable exceptions has mostly disappeared from mainstream programming. While I have nothing against this approach (I worked with and contributed to many of those 30 years ago), I personally have learned (through experience) that 4GL approaches result in compartmentalization and specialties - a large site relying on one of these will need an "expert" trained in that specific UI, which is different to and distinct from any other expertise in Drupal. This becomes a classic case of "job security" over time, since you usually only have one or a few people who know all the ins and outs for the UI, and those experts are needed in order to maintain and update the website. That's why the vast majority of programming is 3GL, with the "modern" and still unproven stuff being 5GL - the entire 4GL is being skipped over now because it never lived up to its promises. I have no desire to go down that rabbit hole again.
Regardless, this is not a referendum on Rules vs ECA. Flag has always has Rules integration and for at least 10 years I have been volunteering to port that from the D7 version to the current versions. Rules has more users than Flag in D10/D11, so I don't see any reason to turn down this offer.
OK, I will hold you to that. It will take me a couple of weeks to open the MRs because I will be on travel until mid-March.
Comment #30
ivnish