-
-
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
add "setFormTheme" and "setFilterTheme" calls + change "initialize" priority #7127
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/DependencyInjection/Compiler/AdminAddInitializeCallCompilerPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* this compiler pass is registered with low priority to make sure it runs after all the other passes | ||
* as we want the "initialize()" calls to come after all the other calls. | ||
* | ||
* @internal | ||
*/ | ||
final class AdminAddInitializeCallCompilerPass implements CompilerPassInterface | ||
dmaicher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
public function process(ContainerBuilder $container): void | ||
{ | ||
$admins = $container->findTaggedServiceIds('sonata.admin'); | ||
foreach (array_keys($admins) as $id) { | ||
$container->getDefinition($id)->addMethodCall('initialize'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/DependencyInjection/Compiler/AdminAddInitializeCallCompilerPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sonata\AdminBundle\DependencyInjection\Compiler\AdminAddInitializeCallCompilerPass; | ||
use Sonata\AdminBundle\Tests\App\Admin\FooAdmin; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class AdminAddInitializeCallCompilerPassTest extends TestCase | ||
{ | ||
public function testProcess(): void | ||
{ | ||
$builder = new ContainerBuilder(); | ||
$builder->register('foo', FooAdmin::class) | ||
->addTag('sonata.admin'); | ||
|
||
(new AdminAddInitializeCallCompilerPass())->process($builder); | ||
|
||
$this->assertSame([['initialize', []]], $builder->getDefinition('foo')->getMethodCalls()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 check if the user has already call
setFormTheme
in the service definition and merge the arguments?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 would say that if you want to set extra form theme, you should do it with a lower priority instead.
For example sonata-project/SonataDoctrineORMAdminBundle#1427
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 mean, if the user has a definition like:
I guess this
setFormTheme
call from the compiler pass will override the parameters previously set in this definition.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.
With this config, what is called first ?
setFormTheme, [['foo.html.twig' ]]
or$definition->addMethodCall('setFormTheme', [$overwriteAdminConfiguration['templates']['form'] ?? []]);
?I would expect the
setFormTheme, [['foo.html.twig' ]]
to be called last and override the global configuration. This would allow to remove a form theme and use another one instead for example. Isn't the case ?But maybe the best would be to expose an
addFormTheme
method instead.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 would say
setFormTheme, [['foo.html.twig' ]]
is called first as it is in the definition of the service, and the compiler pass retrieves this definition, but I don't know.We merge the arguments in the ORM:
https://github.com/sonata-project/SonataDoctrineORMAdminBundle/blob/7493cfffcbe9996316e2dd0cdd9ac5092cf62a18/src/DependencyInjection/Compiler/AddTemplatesCompilerPass.php#L44
Maybe we can do that.
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.
Which one ?
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.
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.
So we are not setting default service calls then anymore, right? If there is no overwrite and no call yet.
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.
maybe like this then? tests pass
so this would never overwrite any existing call
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.
Indeed, since we're doing
As soon as there is no call, we have something to set.