sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Option choice_translation_domain is ignored for expanded choice filters #4550

Closed verheyenkoen closed 4 years ago

verheyenkoen commented 7 years ago

Environment

Sonata packages

$ composer show sonata-project/*
sonata-project/admin-bundle              3.18.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.3.2  Symfony SonataBlockBundle
sonata-project/cache                     1.0.7  Cache library
sonata-project/core-bundle               3.3.0  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.2.1  Symfony SonataDatagridBundle
sonata-project/doctrine-orm-admin-bundle 3.1.4  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.2.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.7.1  Lightweight Exporter library
sonata-project/intl-bundle               2.3.0  Symfony SonataIntlBundle

Symfony packages

$ composer show symfony/*
symfony/assetic-bundle     v2.8.1  Integrates Assetic into Symfony2
symfony/finder             v3.2.8  Symfony Finder Component
symfony/monolog-bundle     v2.12.1 Symfony MonologBundle
symfony/polyfill-apcu      v1.3.0  Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-icu  v1.3.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.3.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php54     v1.3.0  Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions
symfony/polyfill-php55     v1.3.0  Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions
symfony/polyfill-php56     v1.3.0  Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70     v1.3.0  Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util      v1.3.0  Symfony utilities for portability of PHP codes
symfony/security-acl       v3.0.0  Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v2.5.4  Symfony SwiftmailerBundle
symfony/symfony            v2.8.20 The Symfony PHP framework
symfony/var-dumper         v3.2.8  Symfony mechanism for exploring and dumping PHP variables

PHP version

$ php -v
PHP 5.5.38 (cli) (built: Oct  1 2016 23:03:00) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
    with Xdebug v2.5.3, Copyright (c) 2002-2017, by Derick Rethans
    with blackfire v1.10.6-refs/heads/prod+1369-internal, https://blackfire.io, by Blackfireio Inc.

Subject

When you add a choice filter with options expanded set to true and choice_translation_domain set false in the configureDatagridFilters method of a sonata admin, like so:

    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('status', ChoiceFilter::class, array(), ChoiceType::class, array(
                'choices' => [...],
                'expanded' => true,
                'choice_translation_domain' => false,
            ));
    }

... no missing translation errors should be produced.

Instead, Symfony reports missing translations for the choices in the messages domain.

The error is probably here. The variable translation_domain is used instead of choice_translation_domain, and translation should be omitted if choice_translation_domain is false.

verheyenkoen commented 7 years ago

The same error occurs for form fields (not in admin filter). The bug is a little more complicated as it needs 2 twig fixes I think. Not sure if we should open a new issue for that.

greg0ire commented 7 years ago

choice_translation_domain was introduced "recently", right? Not sure if it's an error or a failure to update. Can you determine when it was introduced, and how the native choice field from sf template evolved?

verheyenkoen commented 7 years ago

Was introduced in Symfony 2.7.

I guess all the related changes are in this commit: https://github.com/symfony/symfony/commit/52755ba26d59057bc5642fb97df9454457d06df9.

Sonata has a lot more twig code than that (just for expanded mode) and also different templates for filter fields vs form fields.

greg0ire commented 7 years ago

I think it was introduced a bit earlier, in https://github.com/symfony/symfony/pull/13651/files . The logic is quite natural: use choice_translation_domain if defined and not false, otherwise use whatever was used before. Would you be willing to contribute this?

verheyenkoen commented 7 years ago

I'll try. I was already trying to prove the bug in a unit test. I can do this for the choice_translation_domain=false scenario, but not for the choice_translation_domain='some_custom_domain' (also broken), as the rendered result would be the same as with the default domain (messages).

verheyenkoen commented 7 years ago

I think I could inherit from Symfony\Bundle\FrameworkBundle\Tests\Templating\Helper\Fixtures\StubTranslator and add the translation domain to the annotation (when different than 'messages'), eg.: [trans|my_custom_domain]translation.id[/trans]. Then I would be able to prove the other bug I guess.

Another option is to use the translation profiler but that requires a functional test. All test I've seen till now are building a form and putting it through the render function.

stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

verheyenkoen commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

I'm not doing PHP/Symfony/Sonata Admin anymore so don't know if this still an issue for anyone. Feel free to close.