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 to select a particular user role which could be flagged
You can achieve your requirement by following below steps.
Create a view of type User.
Add a relationship to Flag.
Now add Flags: Flag link field + extra field you want to display
Finally add a ...
5
votes
Accepted
How to list user flags in node
You can relatively easy do that by adding a views contextual filter for the node id (nid) with the following configuration:
When the filter value is NOT in the URL: Provide default value -> ...
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 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 ...
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
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.
3
votes
Accepted
How can I retrieve the value of a field in a flagging?
According to the Flag API
flagging_load
Loads a flagging entity. Parameters
$flagging_id: The 'flagging_id' database serial column.
$reset: Whether to reset the ...
3
votes
Accepted
Flag module integration with Message module
Actually, I tried "Set a data value" action, but was setting wrong variables in it. Using it right way and adding "Save entity" action (I think without this also it may work fine now) worked for me.
...
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
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
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
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
flags × 4757 × 172
views × 146
rules × 96
users × 65
8 × 52
nodes × 37
entities × 31
theming × 24
commerce × 18
ajax × 15
taxonomy-terms × 11
webforms × 11
message-subscribe × 11
emails × 10
panels × 9
notifications × 9
blocks × 8
search × 8
javascript × 7
forms × 6
hooks × 6
comments × 6
organic-groups × 6
rating × 6