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

ChoiceFieldMaskType not working on embedded collection items #4911

Closed lukepass closed 4 years ago

lukepass commented 6 years ago

Environment

CMS built using Symfony 2.8 and Sonata Admin.

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.31.0 3.31.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.11.0 3.11.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/core-bundle               3.9.0  3.9.0  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.3.1  2.3.1  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2  1.0.2  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.4.1  3.4.1  Symfony Sonata / Integrate Doctrine ORM int...
sonata-project/easy-extends-bundle       2.4.0  2.4.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.8.0  1.8.0  Lightweight Exporter library
sonata-project/media-bundle              3.10.0 3.10.0 Symfony SonataMediaBundle
sonata-project/notification-bundle       3.2.0  3.3.0  Symfony SonataNotificationBundle
sonata-project/translation-bundle        2.2.0  2.2.0  SonataTranslationBundle
sonata-project/user-bundle               4.1.0  4.1.0  Symfony SonataUserBundle

Symfony packages

$ composer show --latest 'symfony/*'
symfony/monolog-bundle     v3.1.2  v3.1.2 Symfony MonologBundle
symfony/phpunit-bridge     v2.8.33 v4.0.3 Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.6.0  v1.6.0 Symfony polyfill backporting apcu_* functions to lower P...
symfony/polyfill-intl-icu  v1.6.0  v1.6.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.6.0  v1.6.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php54     v1.6.0  v1.6.0 Symfony polyfill backporting some PHP 5.4+ features to l...
symfony/polyfill-php55     v1.6.0  v1.6.0 Symfony polyfill backporting some PHP 5.5+ features to l...
symfony/polyfill-php56     v1.6.0  v1.6.0 Symfony polyfill backporting some PHP 5.6+ features to l...
symfony/polyfill-php70     v1.6.0  v1.6.0 Symfony polyfill backporting some PHP 7.0+ features to l...
symfony/polyfill-util      v1.6.0  v1.6.0 Symfony utilities for portability of PHP codes
symfony/security-acl       v3.0.1  v3.0.1 Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v2.6.7  v3.1.6 Symfony SwiftmailerBundle
symfony/symfony            v2.8.33 v4.0.3 The Symfony PHP framework

PHP version

$ php -v
PHP 7.1.13-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jan  5 2018 13:26:45) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.13-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

Subject

I have a parent entity which has a collection of OneToMany children. The relationship is working fine and I can add/remove elements using the CollectionType. The problem is that the child entity has a field of type ChoiceFieldMaskType which is working fine when I am editing a single child entity but it doesn't work propertly then used in the parent collection form.

Parent entity:

    /**
     * @ORM\OneToMany(targetEntity="OrientationSurveyQuestion", mappedBy="survey", cascade={"persist", "remove"}, orphanRemoval=true)
     * @ORM\OrderBy({"position"="ASC"})
     */
    private $questions;

Parent form:

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('questions', CollectionType::class, array(
                'by_reference' => false,
                'type_options' => array(
                    'delete' => false,
                ),
            ), array(
                'edit'     => 'inline',
                'inline'   => 'table',
                'sortable' => 'position',
                'limit'    => 15,
            ))
        ;
    }

Child form:

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('position')
            ->add('question')
            ->add('type', ChoiceFieldMaskType::class, array(
                'choices' => array_flip(OrientationSurveyQuestion::getTypeChoices()),
                'map'     => array(
                    OrientationSurveyQuestion::TYPE_TEXT => array(
                        'answerA',
                        'answerB',
                        'answerC',
                    ),
                    OrientationSurveyQuestion::TYPE_IMAGE => array(
                        'answerAImage1',
                        'answerACaption1',
                        'answerAImage2',
                        'answerACaption2',
                    ),
                ),
            ))
            ->add('answerA', null, array(
                'label' => 'a)',
            ))
            ->add('answerB', null, array(
                'label' => 'b)',
            ))
            ->add('answerC', null, array(
                'label' => 'c)',
            ))
            ->add('answerD', null, array(
                'label' => 'd)',
            ))
            ->add('answerAImage1', FileType::class, array(

            ))
            ->add('answerACaption1')
            ->add('answerAImage2', FileType::class, array(

            ))
            ->add('answerACaption2')
        ;
    }

Thanks.

jordisala1991 commented 6 years ago

Do you have any stack trace or javascript debug info we can use to fix the problem?

jordisala1991 commented 6 years ago

Confirmed. It works for 'inline' => 'natural' but not for 'inline' => 'table'

PR created

soullivaneuh commented 6 years ago

The fix introduce an another bug. I have to revert it in #5068.

I reopen this issue.

byhaskell commented 5 years ago

Hey. Still relevant. When about to wait, do not tell me? Not to miss and update your code)

Devristo commented 5 years ago

I also hit this issue now. ChoiceFieldMaskType does not seem to work when used inside a 'inline' => 'table' parent admin.

It seems that the element IDs that the ChoiceFieldMaskType wants to hide do not match the ones generated in 'table' mode.

lukepass commented 5 years ago

Hello, any news on this issue? Can I help somehow? Unfortunately it's still relevant.

Thanks.

sallib commented 4 years ago

Hello, Any news ? I have the same problem with an 'inline' => 'table' parent admin.

Thanks

youngdolphin commented 4 years ago

This bug happens in non collection items too if you have more than 1 property (that uses ModelType or ModelListType in the admin) referencing another entity with a ChoiceFieldMaskType. The first time you open the Add modal for a property in the admin page, the Add modal shows the correct properties and the ChoiceFieldMaskType works fine, but if you open another Add modal for a different property in the same admin page the ChoiceFieldMaskType does not work anymore.

To reproduce: Create an entity with 2 properties referencing another entity with a ChoiceFieldMaskType. The 2 properties use ModelType or ModelListType. In the admin page, click the Add button in both the properties. The first add modal will work fine, the second will show all the properties of the second entity.

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.

lukepass commented 3 years ago

Yes, unfortunately the bug is still here. An ugly workaround is still using "inline": "natural" instead of "table".