craftcms / webhooks

Plugin for integrating Craft with Zapier and IFTTT.
https://plugins.craftcms.com/webhooks
MIT License
84 stars 12 forks source link

Custom FilterInterface not showing up in CP #69

Closed denisyilmaz closed 2 years ago

denisyilmaz commented 2 years ago

Description

Hi, I'm trying to implement a custom Filter for the Webhook plugin. I have a entry type "museum" for which i would like to create a webhook in the CP. I've added a SiteModule and created a custom MuseumFilter which implements FilterInterface:

class MuseumFilter implements FilterInterface
{
    public static function isSelectable(): bool
    {
        return true;
    }

    public static function displayName(): string
    {
        return Craft::t('webhooks', 'Entry has an “Museum” type');
    }

    public static function show(string $class, string $event): bool
    {
        // Only show this filter if the Sender Class is set to 'craft\elements\Entry' 
        return $class === Entry::class;
    }

    public static function check(Event $event, bool $value): bool
    {
        // Filter based on whether the entry's type is 'museum':
        /** @var Entry $entry */
        $entry = $event->sender;
        return ($entry->type->handle === 'museum') === $value;
    }
}

In my SiteModuleI've attached this filter via the Webhooks::EVENT_REGISTER_FILTER_TYPES Event in the init() function:

 Event::on(
            Webhooks::class, 
            Webhooks::EVENT_REGISTER_FILTER_TYPES, 
            function(RegisterComponentTypesEvent $event) {
                $event->types[] = MuseumFilter::class;
            }
        );

But for whatever reason the Filter does not show up in my webhook. Am I missing something?

image

Additional info

denisyilmaz commented 2 years ago

By the way, your example does not mention the isSelectable() function which is needed when implementing FilterInterface:

    public static function isSelectable(): bool
    {
        return true;
    }

is the docs out of sync? Maybe there is something else missing which would explain why the filter does not show up

denisyilmaz commented 2 years ago

… shame on me. i did not bootstrap my custom module.