Closed (outdated)
Project:
Flag
Version:
8.x-4.x-dev
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
5 Jun 2016 at 07:28 UTC
Updated:
19 Feb 2025 at 07:22 UTC
Jump to comment: Most recent
Comments
Comment #2
TheDucksLover commentedThis is what I used to do what you wanna do :
where $flag_id is the machine name of your flag (mine was "bookmarks" so it's a string) and $user_id is the uid of the user... I'd advise you to put this function in your theme.theme file or some generic file so u could use it whereever u want.
Comment #3
joachim commentedDoes the FlagCount service have what you need?
(BTW: please don't add random tags to issues!)
Comment #4
RomanovVlad commented"$result = db_select('flagging', 'f')
->fields('f', array('flag_id'))
->condition('flag_id', $flag_id)
->condition('uid', $user_id)
->countQuery()
->execute()
->fetchField();"
I need the output node number of flags in the announcement.
This code should be put in node.html.twig, then what to put in place
"$user_id"?
Comment #5
joachim commentedUse the FlagCount service.
Comment #6
RomanovVlad commentedUse the FlagCount service.
And how to use FlagCount service? This is a separate module?
Or module setting the flag? (Module version 4.X dev 2016-02-19)
Comment #7
socketwench commentedThe above query is identical to the one we have in FlagCountManager:
Instead of duplicating the query, you could do this instead:
Where $the_flag and $the_user are the flag and user objects respectively.
Comment #8
joachim commented> And how to use FlagCount service? This is a separate module?
Have you actually searched the Flag codebase for 'FlagCount'?
Have you googled to find out about how to use Drupal services?
Comment #9
socketwench commentedYou can call the count service even in your module, Drupal doesn't care. Furthermore, the FlagCountManager caches counts so you don't always have to hit the database with a query.
Comment #10
mfrosch commented@joachim you can check out the flag.services.yml file for getting informations about the services which the module provides.
Here an extended example from @socketwench with flag load
Comment #11
RomanovVlad commentedThanks for the help.
How to get the number of flags in the node?
Comment #12
socketwench commentedAs in the number of flags defined administratively, or the number of times a node has been flagged?
Comment #13
socketwench commentedThere's a getFlags() method on the FlagService.
Comment #14
RomanovVlad commentedHow to use getFlagEntityCount function if content_type="mesto" and flag_id="ponravilos"
What code do I need to insert into html.node.twig
Sorry for my poor English skills and php.
Thank you all for the help
Comment #15
kla2t commented@mfrosch: Employing the flag.count service this way resulted in fatal errors for anonymous users in my case.
I had to get and add a session_id to make it work:
Comment #16
kitzinger commented@kla2t I'm also looking at this, but isn't getSession now deprecated ?
Comment #17
kla2t commented@kitzinger ...don't think so. It seems to be valid up to 8.7.
Comment #18
ivnish5 years without any activity. I think we can close it as outdated. Please reopen if needed.