default Filtering Sonata admin list without a Filter filed

1.1k views Asked by At

I'm using Sonata MongoDb Admin Bundle and I need to filter by default my List data without filter field.

I have a 'tenant_id' attribute in my model and I want to show models only if the tenant_id equal to the id of the connected user.

Any one can help ?

1

There are 1 answers

0
Ugur On BEST ANSWER

You can override createQuery function of Admin class as described here, https://sonata-project.org/bundles/admin/master/doc/reference/action_list.html#customizing-the-query-used-to-generate-the-list

public function createQuery($context = 'list')
{
    $query = parent::createQuery($context);
    $query->field('tenant_id')->equals("YOUR USER ID");
    return $query;
}