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);
// ...
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')...
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 ...
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 ...
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.
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 ...
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(...
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 ...
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
...
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?...
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->...
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 ...
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, ...
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 ...
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. ...
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 ...
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 ...
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 (...
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). ...
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 ...
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->...
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() ...
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 ...
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 ...
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 ...
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.
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 ...
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 ...
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 ...
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: ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
flags × 4787 × 172
views × 147
rules × 96
users × 65
8 × 52
nodes × 37
entities × 31
theming × 24
commerce × 18
ajax × 15
taxonomy-terms × 11
webforms × 11
message-subscribe × 10
emails × 9
panels × 9
notifications × 9
blocks × 8
search × 8
javascript × 7
forms × 6
hooks × 6
comments × 6
organic-groups × 6
rating × 6