Score:1

How can I set a Rules action to unpublish a comment when a specific flag is set?

pe flag

I'm attempting to create a flag that will unpublish a comment when the flag is set on that comment.

I'm attempting to use Rules, Flag, and Rules Flag to achieve this.

The comment type is default 'comment' I'm calling the flag 'unpublish_publish' The flag is global

Where I get stuck is on the Actions portion of the rule creation. For the trigger event I have: After flagging a comment of type Default comments Machine name: rules_flag_entity_flagged:comment--comment

For condition, I have...
Entity is of type Parameters: entity: comment, type: comment

For actions, I have... Set a data value Parameters: data: comment.status.value, value: 0

Something must be wrong. a) Where should I be identifying which flag is involved? There doesn't seem to be any way to do it under conditions. b) I get an error when the rule is enabled...

Drupal\flag\FlagService::getFlagging(): Argument #1 ($flag) must be of type Drupal\flag\FlagInterface, null given, called in ...modules/contrib/rules_flag/src/Plugin/Condition/EntityIsFlagged.php on line 57 in Drupal\flag\FlagService->getFlagging() (line 93 ...

Has anyone achieved this in D8+ and can straighten me out?

pe flag
It's working now without an error (error was apparently a problem with the Flag configuration. It stopped when I changed the type to 'Normal link'). But there is still a problem: there still doesn't seem to be any way to specify which flag is supposed to trigger the rule.
Score:2
ua flag

a) Where should I be identifying which flag is involved?

But there is still a problem: there still doesn't seem to be any way to specify which flag is supposed to trigger the rule.

Yes, currently there is no way to do it... I mean... until a few moments ago, as I have made a patch that adds a "Flag has ID" conditional.

b) I get an error when the rule is enabled...

Clear the cache. If that still doesn't do, make sure you disable the rules that rules_flag pre-installs, as one of them also caused me an "argument #1" error.

pe flag
I see the patch. Thanks! Will test soon. The error stopped after I changed the flag type, so I think that part was something I had wrong in my flag config.
pe flag
Regarding the error: around the same time I changed the flag type I also disabled the default enabled rules, so it's possible that clearing those was also what ended the error in my build.
No Sssweat avatar
ua flag
@aharown07 I am pretty sure that was it.
pe flag
Patch tested. Works for specifying which flag, as a condition.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.