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 "setFormTheme" and "setFilterTheme" calls + change "initialize" priority #7127

Merged
merged 3 commits into from
Apr 30, 2021

Conversation

dmaicher
Copy link
Contributor

@dmaicher dmaicher commented Apr 27, 2021

Subject

I am targeting this branch, because its BC and part of fixing #7104

Changelog

### Fixed
- `AdminInterface::initialize()` is the last method called
- `admin_services.templates.form` is correctly set
- `admin_services.templates.filter` is correctly set
- default service setter calls on `AdminInterface` are only added if there are no calls defined yet

@dmaicher dmaicher requested a review from VincentLanglet April 27, 2021 19:26
@dmaicher dmaicher marked this pull request as ready for review April 27, 2021 19:27
VincentLanglet
VincentLanglet previously approved these changes Apr 27, 2021
@@ -386,7 +386,8 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at
$definition->addMethodCall('setSecurityInformation', ['%sonata.admin.configuration.security.information%']);
}

$definition->addMethodCall('initialize');
$definition->addMethodCall('setFormTheme', [$overwriteAdminConfiguration['templates']['form'] ?? []]);
Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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:

Sonata\AdminBundle\Tests\App\Admin\FooAdmin:
        arguments: [~, Sonata\AdminBundle\Tests\App\Model\Foo, Sonata\AdminBundle\Controller\CRUDController]
        tags:
            - {name: sonata.admin, manager_type: test, label: Foo}
        calls:
            - [ setFormTheme, [['foo.html.twig' ]]]

I guess this setFormTheme call from the compiler pass will override the parameters previously set in this definition.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was 1 failure:

1) Sonata\AdminBundle\Tests\DependencyInjection\Compiler\AddDependencyCallsCompilerPassTest::testProcessResultingConfig
None of the method calls matched the expected method "setRouteBuilder" with arguments Array &0 (
    0 => 'sonata.admin.route.path_info'
) with any invocation order index
Failed asserting that Symfony\Component\DependencyInjection\Definition Object &000000004bf94b930000000046f6a723 (
    'class' => 'Sonata\AdminBundle\Tests\DependencyInjection\Compiler\MockAdmin'
    'file' => null
    'factory' => null
    'shared' => false
    'deprecation' => Array &0 ()
    'properties' => Array &1 ()
    'calls' => Array &2 (
        0 => Array &3 (
            0 => 'setManagerType'
            1 => Array &4 (
                0 => 'orm'
            )
        )
        1 => Array &5 (
            0 => 'setPagerType'
            1 => Array &6 (
                0 => 'simple'
            )
        )
        2 => Array &7 (
            0 => 'setLabel'
            1 => Array &8 (
                0 => 'Foo'
            )
        )
        3 => Array &9 (
            0 => 'setListModes'
            1 => Array &10 (
                0 => Array &11 (
                    'list' => Array &12 (
                        'class' => 'fa fa-list fa-fw'
                    )
                    'mosaic' => Array &13 (
                        'class' => 'fa fa-th-large fa-fw'
                    )
                )
            )
        )
        4 => Array &14 (
            0 => 'setTemplateRegistry'
            1 => Array &15 (
                0 => Symfony\Component\DependencyInjection\Reference Object &000000004bf94ffb0000000046f6a723 (
                    'id' => 'sonata_news_admin.template_registry'
                    'invalidBehavior' => 1
                )
            )
        )
        5 => Array &16 (
            0 => 'setSecurityInformation'
            1 => Array &17 (
                0 => '%sonata.admin.configuration.security.information%'
            )
        )
        6 => Array &18 (
            0 => 'setFormTheme'
            1 => Array &19 (
                0 => Array &20 ()
            )
        )
        7 => Array &21 (
            0 => 'setFilterTheme'
            1 => Array &22 (
                0 => Array &23 ()
            )
        )
    )
    'instanceof' => Array &24 ()
    'autoconfigured' => false
    'configurator' => null
    'tags' => Array &25 (
        'sonata.admin' => Array &26 (
            0 => Array &27 (
                'group' => 'sonata_group_two'
                'label' => '5 Entry'
                'manager_type' => 'orm'
            )
        )
    )
    'public' => true
    'synthetic' => false
    'abstract' => false
    'lazy' => false
    'decoratedService' => null
    'autowired' => false
    'changes' => Array &28 (
        'public' => true
        'class' => true
        'shared' => true
    )
    'bindings' => Array &29 ()
    'errors' => Array &30 ()
    'arguments' => Array &31 (
        0 => 'sonata_news_admin'
        1 => 'Sonata\AdminBundle\Tests\DependencyInjection\Compiler\News'
        2 => 'Sonata\AdminBundle\Controller\CRUDController'
    )
    'innerServiceId' => null
    'decorationOnInvalid' => null
) has a method call to "setRouteBuilder" with the given arguments..

/var/www/SonataAdminBundle/vendor/matthiasnoback/symfony-dependency-injection-test/PhpUnit/DefinitionHasMethodCallConstraint.php:59
/var/www/SonataAdminBundle/vendor/matthiasnoback/symfony-dependency-injection-test/PhpUnit/AbstractContainerBuilderTestCase.php:188
/var/www/SonataAdminBundle/tests/DependencyInjection/Compiler/AddDependencyCallsCompilerPassTest.php:195

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

diff --git a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php
index b7af06402..c4b4508e9 100644
--- a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php
+++ b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php
@@ -338,7 +338,7 @@ class AddDependencyCallsCompilerPass implements CompilerPassInterface
 
             $method = $this->generateSetterMethodName($attr);
 
-            if (isset($overwriteAdminConfiguration[$attr]) || !$definition->hasMethodCall($method)) {
+            if (!$definition->hasMethodCall($method)) {
                 $args = [new Reference($overwriteAdminConfiguration[$attr] ?? $addServiceId)];
                 if ('translator' === $attr) {
                     $args[] = false;

so this would never overwrite any existing call

Copy link
Member

@VincentLanglet VincentLanglet Apr 29, 2021

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

$overwriteAdminConfiguration[$attr] ?? $addServiceId

As soon as there is no call, we have something to set.

@VincentLanglet VincentLanglet requested a review from franmomu April 28, 2021 15:53
@VincentLanglet VincentLanglet added this to the 4.0 milestone Apr 28, 2021
@dmaicher dmaicher force-pushed the issue_7104 branch 2 times, most recently from 68fb22e to 6755dd5 Compare April 29, 2021 17:18
@dmaicher dmaicher requested a review from VincentLanglet April 29, 2021 19:35
@VincentLanglet VincentLanglet merged commit c6f416e into sonata-project:3.x Apr 30, 2021
@VincentLanglet
Copy link
Member

Thanks !

@dmaicher dmaicher deleted the issue_7104 branch April 30, 2021 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants