Search code examples
backendoctobercmsoctobercms-backend

Octobercms Filter scopes options not returned from model class


According to Octobercms documentation I can get the options from a model class method.

But when I try to filter the list I get an undefined index error.

"Undefined index: holiday_type" on line 417 of .../modules/backend/Widgets/Filter.php

What am I doing wrong? I want to get the options from a method via model class

config_filter.yaml

# ===================================
# Filter Scope Definitions
# ===================================

scopes:
    holiday_type:
        label: Holiday Type
        type: group
        conditions: type in (:filtered)
        options: getHolidayTypesAttribute

MyModel.php

public function getHolidayTypesAttribute(){
    return [
        1 => 'default',
        2 => 'new'
    ];
}

Solution

  • You are missing one thing in your config. :) modelClass

    You need to specify which model to use for getting option list if your filter type is group

    scopes:
        holiday_type:
            label: Holiday Type
            type: group
            conditions: type in (:filtered)
            options: getHolidayTypesAttribute
            modelClass: Acme\Blog\Models\Category <- you are missing this
    

    Replace Acme\Blog\Models\Category with your model class and try this it should work

    Reference: October CMS filter scopes options

    if any doubts please comment.