craft-snippets / Craft-quick-filters

Filter widgets for your Craft CMS control panel lists
Other
1 stars 1 forks source link

Feature request - add Verbb Events element type. #10

Open anchovy opened 5 months ago

anchovy commented 5 months ago

Hi, about to purchase this plugin but we also need it to work with verbb events

We've got it working currently via hooking into the EVENT_AFTER_RENDER_TEMPLATE and we've got a controller to add the filters, but it would be preferable and more robust if the element type 'verbb\events\elements\Event' was natively supported.

If you haven't got the time I could do a PR for this?

How we're doing it at the moment in a custom module.

        \yii\base\Event::on(
            \craft\web\View::class,
            \craft\web\View::EVENT_AFTER_RENDER_TEMPLATE,
            function (\craft\events\TemplateEvent $event) {

                //Make sure to install https://plugins.craftcms.com/quick-filters?craft4=
                if(!Craft::$app->plugins->getPlugin('quick-filters'))
                {
                    return;
                }

                //Only run in the elements container
                if($event->template != '_elements/tableview/container'){
                    return;
                }

                //Only run on the Events Page
                $elementType = Craft::$app->getRequest()->getBodyParam('elementType');
                if($elementType == 'verbb\events\elements\Event')
                {
                    $elementType = "events";
                } 
                else{
                    return;
                }

                // inject filters
                $filterService = new \craftsnippets\elementfilters\services\ElementFiltersService();
                $filters = $filterService->getFilters($elementType, 'all');

                $context = [
                    'filters' => $filters,
                ];

                $filtersHtml = \Craft::$app->view->renderTemplate(
                    'quick-filters/_filter-widget-group', 
                    $context,
                    Craft::$app->view::TEMPLATE_MODE_CP
                );
                .....
            }
        ); 
anchovy commented 4 months ago

@piotrpog - I could do a PR for this if that helps?

piotrpog commented 4 months ago

@anchovy Hi, sorry for the late reply. Would your pr add strictly verb event support. I was thinking that maybe i should add some kind of event (not to confuse with verbb event - i mean yii framewrok event) you could attach to and register any kind of new element to have plugin support it.

anchovy commented 4 months ago

Hi @piotrpog I was only thinking about verbb events, but your solution would be much better and flexible going forward.