Add method to easily extend filter scopes (#2866)

* Add method to easily extend filter scopes
* Add non static method for filter scope extension
This commit is contained in:
CSNWEB 2017-05-14 01:31:09 +02:00 committed by Luke Towers
parent 95cd3f7077
commit fe3e44efeb
1 changed files with 32 additions and 0 deletions

View File

@ -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]);
});
}
}