Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently it is - as far as I understand - not possible to calculate with flag counts. There is an event raised when a certain number of flags is set, which doesn't allow for much accuracy.
I think it should be possible to fetch a flag's overall count as well as the count of flags set for a certain entity.
Comments
Comment #1
Tafa CreditAttribution: Tafa commentedIt would be great to be able use such features indeed as i am in a similar situation trying to use the flag count with rules.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedAnother way to fix this issue would be to correct the project page. I.e. replace "Full Rules module integration" with "Partial Rules module integration".
Full integration means to provide all the relevant module data to Rules. Currently, Rules support is limited to toggeling flags and react on flagging events with certain thresholds.
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedI ran into this issue again (for another use-case). Had a look at the code, but my knowledge of Rules API is limitted. Please somebody assist. I can't believe it would be a great effort to add flag counts support to rules.
Comment #4
Scyther CreditAttribution: Scyther commentedI will make a new Rules action so you can get the flag count.
Start with the 7.x-3.x and then backport.
Comment #5
shabana.navas CreditAttribution: shabana.navas commentedI have added the rules action to get the overall flag count and to get the flag count for a specific entity to the 7.x-3.x version. Please test it out.
Comment #6
joachim CreditAttribution: joachim commentedThanks for working on these Rules issues :)
Quick eyeball review:
The @return documentation shouldn't have a variable name.
Remember to trim whitespace :
Are we changing the return of this, or is it just diff being weird?
Comment #7
shabana.navas CreditAttribution: shabana.navas commentedI have attached the updated patch.
Actually, the return type for that function was wrong. It wasn't returning an array of flags, so I changed the comment.
Comment #8
shabana.navas CreditAttribution: shabana.navas commentedForgot to change the comment no. on the patch title. Here's the patch again.
Comment #9
oystercrackher CreditAttribution: oystercrackher commented@shabana
If I have flag for "Like Node" which enables users to like various nodes. Will the patch enable me get the number of nodes a user has flagged as like?
I am trying to do the following and want to see if this patch is designed to help:
Event- Node is flagged as "Like Node"
Condition- User has role
Action- Fetch Content Flagged By User
Action- If flag count < 10 (Your patch??) I'm using Conditional Rules module as well.
Action- Grant Points To User
Any help is greatly appreciated.
Thanks
Comment #10
shabana.navas CreditAttribution: shabana.navas commented@oystercracker, I haven't tested this in conjunction with the Conditional Rules module, however, I believe it should work. Basically, with the 'Fetch overall flag count' you can get the total count of the 'Like node' flag and then, you can set up your condition for it to be for a certain user. I am not sure how Conditional Rules work, as I haven't used it yet, but I guess you can use it to add the condition, only if the 'overall_flag_count' field is less than 10.
Hope this helps.
Comment #11
oystercrackher CreditAttribution: oystercrackher commented@Shabana
The patch applied successfully without errors and your options do appear but do not work for my use case above. For my case, I would need to be able to get the user's flag count for a certain flag then be able to do a comparison of the count. Do you know how I might implement an action into rules to get the user's flag count for a certain flag?
Thanks in advance,
Comment #12
shabana.navas CreditAttribution: shabana.navas commentedI have now incorporated a new rule action to get the user's flag count as well. Thanks for bringing to light the use case. As @oystercrackher just did, I hope a lot more users can post features that they would like to be added to Flags, so that it can be better integrated with Rules. My site only implements Rules with Flags for simple use cases.
Consequently, it would be very helpful if you guys can post Rules features which you believe should definitely be part of Flags 7.x-3.x.
Comment #13
SGhosh CreditAttribution: SGhosh commentedPatch in #12 tested and confirmed.
My only feedback for this would be -
* Fetch overall flag count - the name is not very self-explanatory: it actual fetches the total no. of nodes that are flagged under a given flagged. So content A flagged by multiple users, yet this action will return 1.
My feedback: Change name to Fetch overall flag count for entity/node
Comment #14
shabana.navas CreditAttribution: shabana.navas commentedActually, I think you've misunderstood the function. 'Fetch overall flag count' gets the total count of items flagged within a flag. It is not just the count of the total number of nodes that are flagged, but it grabs every entity type flagged within a flag, including nodes. So, I think the name is appropriate.
Comment #15
shabana.navas CreditAttribution: shabana.navas commentedCommitted to 7.x-3.x-dev.