Dynamically add list filter when none exist in the original listConfig
0
When a controller uses the ListController behavior and no filter has been defined in its config_list.yaml, this trick will allow you to dynamically create one.
Controllers\MyController::extend(function ($controller) {
if (!$controller->listConfig) {
// controller uses the default value
$controller->addDynamicProperty('listConfig', 'config_list.yaml');
}
$listConfig = $controller->makeConfig($controller->listConfig);
if (!isset($listConfig->filter)) {
// no filter defined in config_list.yaml, let's create one
$listConfig->filter = [
'scopes' => [
'myScope' => [
'type' => 'checkbox',
'label' => 'Apply My Scope',
'default' => false,
'conditions' => 'mod(id,2)',
],
],
];
}
$controller->listConfig = $listConfig;
});
Note: if a filter already exists, use the extendListFilterScopes()
method.
ref. https://wintercms.com/docs/backend/lists#extend-filter-scopes
There are no comments yet
Be the first one to comment