Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to disable global_search #1683

Closed
BillyMorgan opened this issue Apr 8, 2024 · 5 comments
Closed

Add the ability to disable global_search #1683

BillyMorgan opened this issue Apr 8, 2024 · 5 comments
Labels

Comments

@BillyMorgan
Copy link

I'm not entirely sure if this is a bug, or a feature, or me being a dolt but I wanted to exclude the user admin from the global search and the only way I could do it was to completely re-implement the service like this:

  sonata.user.admin.user:
    class: Sonata\UserBundle\Admin\Model\UserAdmin
    arguments:
      $userManager: '@sonata.user.manager.user'
    autowire: false
    autoconfigure: false
    tags:
      - name: sonata.admin
        model_class: Entity\User
        group: sonata_user
        manager_type: orm
        global_search: false
        label: users
        translation_domain: SonataUserBundle
        label_translator_strategy: sonata.admin.label.strategy.underscore
        icon: <i class='fa fa-users'></i>

All of this, just because I needed to add global_search: false. Is there already a better way to do this? If not, is the correct fix to extend the configuration to allow for the extra tag attribute? If so, I could give it a crack.

@VincentLanglet
Copy link
Member

If not, is the correct fix to extend the configuration to allow for the extra tag attribute?

This feel weird cause if we start adding such config, it would be expected to have

  • the same in every other Sonata bundles
  • the same for every other tag attributes like label, icon, and so on

Best would be an entry point on SonataAdminBundle, if it doesn't exist already.

I see multiple solutions:

public function search(...) {
     if ($admin instanceof UserAdminBundle) {
         return null;
     }

     parent::search(...);
}
if (false === $admin->isSearchEnabled()) {
     return null;
}

so it would have been easier to set the value be decorating the admin with an admin extension...

@BillyMorgan
Copy link
Author

BillyMorgan commented Apr 8, 2024

@VincentLanglet Thanks for your help and suggestions. I agree it would be a slippery slope having to allow for every potential config option.

Before I go on, please let me prefix this with an apology: Sorry, for only whinging and not offering any solutions. I'd help if I had the time but currently it's not an option for me. I feel like I need to mention this in case someone else comes along with the same issue:

First, you can already decorate the SearchHandler

It seems like you can't realistically do that with the code in it's current state. At least not without making and even bigger mess than what I have in my original "solution".
The Search handler is mentioned as a concrete class multiple times in the library (i.e. no interfaces). Even if you do decorate it by defining sonata.admin.search.handler in services.yaml, you then need to basically clone and redefine the Sonata\AdminBundle\Block\AdminSearchBlockService to accept the new decorated handler because the service is declared final and has a private dependency on a concrete Sonata\AdminBundle\Search\SearchHandler.

@VincentLanglet
Copy link
Member

First, you can already decorate the SearchHandler

It seems like you can't realistically do that with the code in it's current state. At least not without making and even bigger mess than what I have in my original "solution". The Search handler is mentioned as a concrete class multiple times in the library (i.e. no interfaces). Even if you do decorate it by defining sonata.admin.search.handler in services.yaml, you then need to basically clone and redefine the Sonata\AdminBundle\Block\AdminSearchBlockService to accept the new decorated handler because the service is declared final and has a private dependency on a concrete Sonata\AdminBundle\Search\SearchHandler.

Good point, does sonata-project/SonataAdminBundle#8170 would solve your issue ?

@BillyMorgan
Copy link
Author

Certainly looks like it would help :)

@VincentLanglet
Copy link
Member

I release 4.30.0 from SonataAdmin so I think we can close this now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants