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

Show Action with FormType::class fields #4593

Closed RonFire closed 6 years ago

RonFire commented 7 years ago

Environment

Sonata packages

sonata-project/admin-bundle 3.20.1 sonata-project/block-bundle 3.3.2 sonata-project/cache 1.0.7 sonata-project/core-bundle 3.4.0 sonata-project/datagrid-bundle 2.2.1 sonata-project/doctrine-orm-admin-bundle 3.1.6 sonata-project/exporter 1.7.1

Symfony packages

symfony/monolog-bundle v3.1.0 symfony/phpunit-bridge v3.3.6 symfony/polyfill-apcu v1.4.0 symfony/polyfill-intl-icu v1.4.0 symfony/polyfill-mbstring v1.4.0 symfony/polyfill-php56 v1.4.0 symfony/polyfill-php70 v1.4.0 symfony/polyfill-php72 v1.4.0 symfony/polyfill-util v1.4.0 symfony/security-acl v3.0.0 symfony/swiftmailer-bundle v2.6.3 symfony/symfony v3.3.6

PHP version

PHP 7.0.7 (cli) (built: May 27 2016 11:13:44) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

Subject

Hello Sonata Team,

I am currently trying to implement the EntityAuditBundle you mention in your Documentation (https://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/audit.html)

Since the comparison builds on the Show Action i therefore wanted to make that work. There i am having a Issue with showing fields which are handled by embedded forms like this:

$formMapper
    ->add('socialmedia', SocialMediaType::class, array(
         'label' => false,
     ))
;

this SocialMediaType represents an Embeddable.

Another Usecase is with other real Entities used:

$formMapper
    ->tab('e-Learning')
        ->with('e-Learning')
            ->add('elearning', ElearningType::class, array(
                    'label' => false,
             ))
        ->end()
    ->end()
;

Since a description of how to implement these into the configureShowFields function i am quite desperate on how to use these to show the fields which are defined in those FormTypes.

I hope someone is able to help me on this one.

Best regards, Ronald

sirbaconjr commented 7 years ago

If I understood it right, you want to use the SocialMediaType in the show view? I never tried to do this, but here is something that works for me. Use the sub entity fields.

$showMapper
    ->add('socialMedia.name')
;

If you need specific fields, check this.

jordisala1991 commented 6 years ago

As @ejkun said showMapper works different than the formMapper and there are docs for it too.

Closing.