Problem/Motivation

I would like to be able to execute some of my own code when spam is detected.

It would be useful if there was an event dispatched that custom modules could subscribe to.

I will try to add a MR

Issue fork spambot-3543693

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

loze created an issue. See original summary.

loze’s picture

There is the hook spambot_registration_blocked that is invoked on both user registration and webform submissions.

But no hook is triggered when spam is detected on a cron run.

nickdickinsonwilde’s picture

Status: Active » Needs work

Sounds like a great idea. I see a branch, but I don't see any commits there. can you try again?

loze’s picture

Status: Needs work » Needs review

The MR adds a new event Drupal\spambot\Event\SpamDetectedEvent
which is dispatched from spambot_cron()
The event carries the detected account, available via getAccount(), so custom modules can subscribe and run their own code:

public static function getSubscribedEvents(): array {
    return [SpamDetectedEvent::EVENT_NAME => 'onSpamDetected'];
  }
  
  public function onSpamDetected(SpamDetectedEvent $event): void {
    $account = $event->getAccount();
    // React to the detected spammer.
  }