14 votes
Accepted

How can I flag content programmatically?

Here's how to flag or unflag an entity programmatically, using the Flag service. $flag_id = 'bookmark'; $flag_service = \Drupal::service('flag'); $flag = $flag_service->getFlagById($flag_id); // ...
oknate's user avatar
  • 14.3k
13 votes

How can I flag content programmatically?

Flag for a certain user you will have to do : $account = \Drupal::currentUser(); // or load a specific user $flag_service = \Drupal::service('flag'); $flag = $flag_service->getFlagById('bookmark')...
romain ni's user avatar
  • 837
8 votes
Accepted

View, flag, and followers

Whether you're creating content or user Views, you have to add the Flags Relationship (User flag in your case). This is the first step to introducing the flags information into the Views, and in most ...
prkos's user avatar
  • 7,131
6 votes

How to create custom rules action event conditions?

A "universal formula or module to create custom rules actions, events and conditions" (as is your question), is to write a custom module. To do so, you either create a new module, or you extend any of ...
Pierre.Vriens's user avatar
6 votes
Accepted

Drupal 8 - How to Reference Flags Twig Template without showing full content?

FOUND IT Alright guys, so it's simple. You reference the flag this way in your Twig Templates: {{ content.flag_machinename }} Cheers.
Narayan Dheeraj Kumar's user avatar
6 votes
Accepted

How to change the labels TRUE and FALSE of a boolean field in views exposed filter

There is a number of ways how to do it, check out this thread for a lot of suggested options: Change the '- Any -' text in an exposed taxonomy filter. You can change the themed output for that form ...
prkos's user avatar
  • 7,131
5 votes
Accepted

How can I write into a Flag's custom field programmatically?

I fix it with this code. You should save the output of the function $flag_service->flag($flag, $entity); //Wrong method in a variable like it $id_flagged_entity = $flag_service->getFlagging(...
Sim_Lcc's user avatar
  • 66
4 votes
Accepted

How can I show list of users that bookmarked article?

If you really want to do this with Views you will need the following: A Content View for articles with a Nid as a Contextual Filter, in order to limits the results to the article node you are ...
Stefanos Petrakis's user avatar
4 votes
Accepted

How to show data of user that flagged a content(2 flag types)?

Add a filter for the whole view that checks username in both fields as not null, and set the operator to 'And'. In your view under 'Filter Criteria' do the following: Add user name with the first ...
Jed_BH's user avatar
  • 421
4 votes
Accepted

How to redirect user to an url when node is flagged?

You need to use the event, After saving new flagging Add Condition of Flag, and enter flag machine name Add action of Page redirect, enter the url where you want to redirect. Ex: /node/1 Important ...
No Sssweat's user avatar
  • 31.3k
4 votes
Accepted

How to redirect user to login page when anonymous user click on the flag link?

I have handled this by only showing the flag element when the user is logged in. When the user is not logged in, I have rendered out the flag graphic (eg, the heart) as a link to 'user/login?...
mpdonadio's user avatar
  • 38.1k
4 votes
Accepted

How can I get flag count of a flag?

For flag count on entities use: $flag_service = Drupal::service('flag.count'); $counts = $flag_service->getEntityFlagCounts($node); For flag count on flag entity use: $flag_service->...
DiDebru's user avatar
  • 851
4 votes
Accepted

How to count the number of comment and flag in a node?

For the comment count you can get it in the node twig by: {{ content.comment['#items'].comment_count }} But the flag count i think there is no way to get it directly in the twig: There is extension ...
berramou's user avatar
  • 7,185
4 votes

How do you target a specific type of content?

You need to configure your moderate_node flag in either the UI or in configuration management. In the flag module, a flag entity is defined by the entity type (i.e. node) and bundles (e.g. article, ...
Shawn Conn's user avatar
  • 26.9k
3 votes

Give flagged products in search API a higher search score?

You could have a view that shows flagged nodes by user and a view attachment for the index filtering out nodes that the user has flagged.
Niall Murphy's user avatar
  • 2,771
3 votes
Accepted

How to mark a node as read per user?

Using the Flag, Views and Rules modules (as in your question) is indeed a way to get this to work. But assuming you have way more then just 2 (= a+b) users, you probably also want to add the Views ...
Pierre.Vriens's user avatar
3 votes

How to create missing rules event when user flags a statuses updates?

Preface - start This answer assumes you're using the current version of Flag, i.e. 7.x.-3.x. Though a comment below this answer states: Statuses is not compatible with flag 3. It works with flag 2. ...
Pierre.Vriens's user avatar
3 votes

How to create missing rules event when user flags a statuses updates?

Umair, have you looked at the patches in drupal.org/node/1787930 and drupal.org/node/1311468 and maybe some others ? I got flag 3 working with the status + rules, but not the comments. It could be ...
Niall Murphy's user avatar
  • 2,771
3 votes
Accepted

How to access commerce_product field of line-items using Rules to flag the Commerce Product?

Below is a possible approach you can use to solve your question. It provides the details about how I was able to have a set of Drupal messages being shown at checkout time, which look similar to this ...
Pierre.Vriens's user avatar
3 votes
Accepted

How can I track all Flagging/Unflagging history for statistics?

Yes there is a way ... using a combination of these (commonly used) modules: Rules Message Views Long story short: Create a "Message Type" that you'll use for creating some type of custom logging (...
Pierre.Vriens's user avatar
3 votes
Accepted

How to use "replacement tokens" created for a Message type in Views?

"To add profile pics of both user/team member or the email or any information in the view ..." (as in your question), you cannot use the replacement tokens (= @utilisateur and @equipier in your case). ...
Pierre.Vriens's user avatar
3 votes
Accepted

How do I make a link to a flag edit page?

I'm not sure about any view field for an edit link, but you can link to the flag's edit screen, like most entities, in a number of ways. Looking at the module's flag.routing.yml file, we see the edit ...
sonfd's user avatar
  • 7,921
3 votes
Accepted

How do you target a specific type of content?

If you want your hook code to only run on specific content types, simply add a conditional function admin_task_notify_node_update(Node $node) { if ($node->getType() == 'article' || $node->...
No Sssweat's user avatar
  • 31.3k
3 votes
Accepted

Unable to display message when account is flagged

There's no need to implement three times your flag service, once is enough (same for your user to flag). The error says Message TypeError : Argument 1 passed to Drupal\flag\FlagService::getFlagging() ...
MacSim's user avatar
  • 804
3 votes
Accepted

How to unflag/reset a flag again, when matching some conditions in onFlag event?

I'm guessing the problem is that in the onFlag event, the flag is still being created, so it can't be unflagged because it hasn't been fully saved yet. But I think the bigger problem is that your code ...
Patrick Kenny's user avatar
2 votes

How to display a flag to anonymous users?

https://www.drupal.org/project/flag_anon Offer an option to display of "sign in or register" for a flag for anonymous users.
user24957's user avatar
  • 341
2 votes

How do I mass flag a node on behalf of users (possibly with VBO)?

What you could do to get this to work, is to use the integration of VBO with the Rules module, as further detailed below. Step 1: Create a Rules Component Create a (rather basic) Rules component to ...
Pierre.Vriens's user avatar
2 votes

How can I update a user flag in rules?

My question: how can I fetch the previously applied flag in rules so that I can update the timestamp and re-save it? Some good news but mostly bad. If you add an extra text field to the flag and ...
Niall Murphy's user avatar
  • 2,771
2 votes

How to refresh a coded block when a flag is clicked in it?

The easiest way would be to use the module Block Refresh. With this module you can set up any block to be reloaded both manually and by an interval. For your use case you would chose the first option, ...
user5950's user avatar
  • 2,038

Only top scored, non community-wiki answers of a minimum length are eligible