1

The current issue is that I have multi-site setup, where are many different sites in a single Craft instance, e.g., I have 10 websites from 10 customers, when one customer updates his website I want Webhook to be triggered only for his website, not all 10 sites at once. How could I achieve this, is there a filter where I can do it like {{event.site.name == "someSite2Handle"}} in a debouncer or anything like that?

1 Answer 1

1

First of all, using multi-site for 10 different customers doesn't sound like what it is intended to be used for. But regardless, assuming you are using the Webhooks plugin, you can create your own additional filter that checks for the site ID you are interested in.

use yii\base\Event;
use craft\webhooks\Plugin as Webhooks;
use craft\events\RegisterComponentTypesEvent;

Event::on(
    Webhooks::class, 
    Webhooks::EVENT_REGISTER_FILTER_TYPES, 
    function(RegisterComponentTypesEvent $event) {
        $event->types[] = SiteFilter::class;
    }
);
use Craft;
use craft\webhooks\filters\FilterInterface;
use craft\elements\Entry;
use yii\base\Event;

class SiteFilter implements FilterInterface
{
    public static function displayName(): string
    {
        return 'Entry is in site with ID 1';
    }

    public static function show(string $class, string $event): bool
    {
        return $class === Entry::class;
    }

    public static function check(Event $event, bool $value): bool
    {
        $entry = $event->sender;

        return ($entry->siteId == 1) === $value;
    }
}
2
  • The check methods is not working. I've done this instead : $entry = $event->sender; return ($entry->siteId == 1) === $value; Commented Aug 26, 2022 at 15:17
  • Great, I've updated my answer accordingly.
    – Ben Croker
    Commented Aug 26, 2022 at 19:36

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.