diff --git a/modules/backend/behaviors/ListController.php b/modules/backend/behaviors/ListController.php index 91baff00c..6cbd5a924 100644 --- a/modules/backend/behaviors/ListController.php +++ b/modules/backend/behaviors/ListController.php @@ -240,6 +240,13 @@ class ListController extends ControllerBehavior $filterWidget->bindEvent('filter.update', function () use ($widget, $filterWidget) { return $widget->onRefresh(); }); + + /* + * Filter Widget with extensibility + */ + $filterWidget->bindEvent('filter.extendScopes', function () use ($filterWidget) { + $this->controller->filterExtendScopes($filterWidget); + }); /* * Extend the query of the list of options @@ -449,6 +456,15 @@ class ListController extends ControllerBehavior public function listExtendColumns($host) { } + + /** + * Called after the filter scopes are defined. + * @param \Backend\Widgets\Filter $host The hosting filter widget + * @return void + */ + public function filterExtendScopes($host) + { + } /** * Controller override: Extend supplied model @@ -543,4 +559,20 @@ class ListController extends ControllerBehavior call_user_func_array($callback, [$widget, $widget->model]); }); } + + /** + * Static helper for extending filter scopes. + * @param callable $callback + * @return void + */ + public static function extendFilterScopes($callback) + { + $calledClass = self::getCalledExtensionClass(); + Event::listen('backend.filter.extendScopes', function ($widget) use ($calledClass, $callback) { + if (!is_a($widget->getController(), $calledClass)) { + return; + } + call_user_func_array($callback, [$widget]); + }); + } }