-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow to disable the global search by admin #6609
Conversation
{ | ||
public const TAG_ATTRIBUTE_TOGGLE_SEARCH = 'global_search'; | ||
|
||
private const TAG_DMIN = 'sonata.admin'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private const TAG_DMIN = 'sonata.admin'; | |
private const TAG_ADMIN = 'sonata.admin'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this tag is used in multiple compiler pass. It should be the same constant, isn't it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I see this tag is used in other classes, but since we haven't defined a global place where it could be declared, I decided to use this only for the purposes of this class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we declare this in the AdminInterface ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, we should not tie the classes outside the Symfony specific DI scope with something related to that configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I think the tag should be in AddDependencyCallsCompilerPass
which should mention Admin in the name (and maybe be splitted ?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add the constant at AddDependencyCallsCompilerPass
in a new pedantic PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added it here: #6614
WDYT ?
c44a8cc
to
1670087
Compare
Do you know how to fix the PHPStan issue without widening the allowed types in the docblock? I would not like to add an ignore rule. |
I would say you cant since we're trusting the Phpdoc. Either the phpdoc say that it should be an array of bool, either there is a check inside ; but phpstan doesnt allow to do both. |
I don't know if we should mark as |
Thanks for the feedback. |
/** | ||
* @author Javier Spagnoletti <[email protected]> | ||
*/ | ||
final class AdminSearchCompilerPassTest extends TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using AbstractCompilerPassTestCase
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I thought I had written something more in the previous comment. What I meant was to use that class to make the test simpler and to use real objects, something like:
$adminFooDefinition = new Definition(PostAdmin::class);
$adminFooDefinition->addTag('sonata.admin', ['global_search' => true]);
$this->setDefinition('admin.foo', $adminFooDefinition);
$adminBarDefinition = new Definition(PostAdmin::class);
$adminBarDefinition->addTag('sonata.admin', ['global_search' => false]);
$this->setDefinition('admin.bar', $adminBarDefinition);
$adminBazDefinition = new Definition(PostAdmin::class);
$adminBazDefinition->addTag('sonata.admin', ['some_attribute' => 42]);
$this->setDefinition('admin.baz', $adminBazDefinition);
$searchHandlerDefinition = new Definition();
$this->setDefinition('sonata.admin.search.handler', $searchHandlerDefinition);
$this->compile();
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
'sonata.admin.search.handler',
'configureAdminSearch',
[['admin.foo' => true, 'admin.bar' => false]]
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I've applied your suggestion.
|
||
private const TAG_ADMIN = 'sonata.admin'; | ||
|
||
public function process(ContainerBuilder $container): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try to extract some smaller methods to reduce complexity?
Thanks @phansys |
Subject
Allow to disable the global search by admin.
I am targeting this branch, because these changes respect BC.
Closes #6102.
Changelog
To do