Skip to main content
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.4k
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
  • 857
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,161
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,161
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 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.5k
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
  • 861
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,213
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

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

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
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
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
  • 8,027
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.5k
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
  • 814
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 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 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
Accepted

How to create a User Feed using the modules Message and Flag?

If you'd add the Rules module (on top of the Message and Flag module you're already using), you can get this to work by using the "Replacement tokens" as part of your "Message type" configuration. If ...
Pierre.Vriens's user avatar
2 votes

How to display a Flag in a tpl file for different View modes?

You actually can display a Flag link as a pseudofield, which can be ordered among other entity elements in the Manage display settings for an entity type. Go to admin/structure/flags and pick the Flag ...
Jeroen's user avatar
  • 2,518
2 votes
Accepted

Add 2 flag fields of 2 types of flag to views field

You may be able to do this with native views. Using field rewriting in views you can insert values into field display originating from other fields in the same row if they are ordered to appear ...
Remog's user avatar
  • 561
2 votes
Accepted

How to schedule a Rules component at the end of the month?

Introducing last day of 23:59 works for me (last day of is the last day of the current month, and 23:59 just before the day ends). You can see the full reference of DateTime relative formats here: ...
dinopmi's user avatar
  • 2,587

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