Add List Filter via Code

I would like to apply a filter to a backend list. But since I build some kind of default model/controller setup which should be extendable, I would like to apply those filters via code.

The idea:

  • Define them in a config_filter.yaml
  • Parse this file like this:
    $baseFilters = (array) Yaml::parseFile(plugins_path('namespace/plugin') . '/controllers/basetagscontroller/config_filter.yaml');
  • Add the filters to the list via code.

Inside my controller, I also extended the columns inside listExtendColumns() with some default columns.

Now I would like to use $list->addFilter() to apply the filter, but I couldnt get it to work and didnt find an example anywhere.

Could you deliver a quick example on how to do this please?

Thanks a lot ^^

Nvm I found it out:

I added this event to the listGetConfig() function within the controller and it worked fine.

Not sure if this was the best spot to register the event listener, but it works. ^^