Closed (fixed)
Project:
Flag
Version:
5.x-dev
Component:
Flag core
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
17 Aug 2023 at 11:26 UTC
Updated:
3 Sep 2025 at 14:39 UTC
Jump to comment: Most recent
As far as I can see, there is no method to get all flags for a particular user.
n/a
Add a method to \Drupal\flag\FlagService - perhaps call it getFlagsByUser
1. add the method
2. use it in \Drupal\flag\FlagService::unflagAllByUser
none
Add new method on FlagService
none
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
viren18febs commentedI am working on it.
Comment #4
malcomio commented@viren18febS thanks but I just created a merge request for this: https://git.drupalcode.org/project/flag/-/merge_requests/49
Comment #6
joelpittetThanks I just caught up the code, it was failing on some cleaned up namespace use statements. We are using this and it's very helpful, thank you @malcomio. I manually reviewed the code, and the abstraction is nice clean-up for the unflagAllByUser()
Comment #7
ivnishPlease fix https://git.drupalcode.org/issue/flag-3381654/-/jobs/4104065
Comment #9
joelpittetLooks like the issues were corrected, thanks Ramil g. The remaining are unrelated phpstan for other tests, not appropriate to fix here.
Comment #10
ivnishGood work, but needs tests
Comment #11
joelpittetTests added, back to RTBC.
Comment #12
ivnishLooks good for me. Waiting for @Berdir opinion.
Comment #14
ivnishSorry, already fixed here #2769303: add a service method to get all of a user's flagged entities for a given flag. Credits will be added
Comment #15
joelpittet@ivnish, I think this one’s actually a different use case, so reopening as RTBC 🙂
The diff:
getFlagUserFlaggings($flag, $user): Only returns the user’s flaggings for a specific flag.getAllFlaggingByUser(?$account, $flag = NULL, $session_id = NULL): Returns all flaggings for a user, with extra handling for anonymous users via session ID.Since
getFlagUserFlaggings()already covers the per-flag case, maybe we could simplifygetAllFlaggingByUser()to just handle “all by user” and drop the “optionally narrowed by flag” bit? That way each method has a clear, distinct role.Looks like you’re targeting 5.x, so I’ve moved it over there.
Comment #17
ivnishAh, sorry)
Could you update the MR ?
Or... I can revert my commit and use yours, because it more complex
Comment #19
joelpittet@ivnish woah, you’re quick! I was juggling branches since I couldn’t retarget the MR to 5.x, so I created a new one and moved the code over.
Totally up to you, but my thought is to keep the signature specific to “all flags for user,” so the distinction between the two methods stays clear.
Comment #20
joelpittetThanks for retargetting the code in MR 49 to 5.x branch. I will put my proposal in MR 156 since they are now both on 5.x
Comment #21
joelpittetI added
populateFlaggerDefaults()because I think we were missing that, and removed the $flag because that use-case is covered by the other issue. Moving to Needs Review, maybe you can have a look @ivnish?Comment #23
ivnishLGTM
if no more code updates are planned, I think I can commit this
Comment #24
joelpittet@ivnish I am good with committing this as-is. We could test session too but there are probably other tests already checking for that condition as we copied from other service methods. So 🚀
Comment #26
ivnishThanks!
Comment #27
joelpittetAwesome, thanks for giving the feature a second thought!