1

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?

1
  • 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.
    – aharown07
    Jan 11, 2023 at 0:39

1 Answer 1

2

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.

4
  • 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.
    – aharown07
    Jan 12, 2023 at 2:21
  • 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.
    – aharown07
    Jan 12, 2023 at 17:18
  • @aharown07 I am pretty sure that was it.
    – No Sssweat
    Jan 12, 2023 at 17:38
  • Patch tested. Works for specifying which flag, as a condition.
    – aharown07
    Jan 12, 2023 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.