I have developped an online learning website with EasyAdmin as backend. Everything works fine, but I'd like to hide or disable the search bar on top of the crud pages. I have not overridden any templates, just created crud based on my entities with fields and a custom query builder to only index content created by the logged in user. Can't seem to find any info on how to do it online or in the doc. Is it possible to add an option to hide or disable the default search bar? Thank you!
CodePudding user response:
https://symfony.com/doc/3.x/EasyAdminBundle/crud.html#search-order-and-pagination-options
In your Dashboard (eg. App\Controller\Admin\DashboardController
):
public function configureCrud(): Crud
{
$crud = Crud::new();
return $crud
// ...
->setSearchFields(null); // this will hide the search bar on all admin pages
}
That's what you asked for. But you can go further:
-> Hide the search bar only on a specific CrudController:
public function configureCrud(Crud $crud): Crud
{
return $crud
// ...
->setSearchFields(null);
}
-> Add conditions for granular control:
public function configureCrud(Crud $crud): Crud
{
if (
$_GET['crudAction'] === Action::EDIT // if this is the 'edit' page
|| !in_array('ROLE_ADMIN', $this->getUser()->getRoles()) // if the user is not admin
) {
$crud->setSearchFields(null);
}
return $crud;
}
Please validate this answer if it matches what you asked for.