phpsymfonysonatasonata-media-bundle

Preview column disappears when modifying Sonata Media Bundle


I am modifying the Sonata Media Bundle's media admin screen to show a new field. After using the Easy Extends tool to extend the bundle, I create a very small class to do this with:

namespace App\Application\Sonata\MediaBundle\Admin\ORM;

use Sonata\AdminBundle\Form\FormMapper;
use Sonata\MediaBundle\Admin\ORM\MediaAdmin as BaseMediaAdmin;

class MediaAdmin extends BaseMediaAdmin
{
    /**
     * {@inheritdoc}
     */
    protected function configureFormFields(FormMapper $formMapper)
    {
        parent::configureFormFields($formMapper);

        $formMapper
            ->add(
                'language',
                null,
                []
            )
            ->end();
    }
}

... and I add this in my services.yaml file:

sonata.media.admin.media:
    class: App\Application\Sonata\MediaBundle\Admin\ORM\MediaAdmin
    arguments:
        - ''
        - '%sonata.media.admin.media.entity%'
        - '%sonata.media.admin.media.controller%'
        - '@sonata.media.pool'
        - '@sonata.media.manager.category'
    tags:
        - { name: sonata.admin, manager_type: orm, group: admin, label: Seiten }
    public: true
    calls:
        - [ setModelManager, ["@sonata.media.admin.media.manager"] ]
        - [ setTranslationDomain, ["%sonata.media.admin.media.translation_domain%"] ]
        - [ setTemplates, [ inner_list_row : "@@SonataMedia/MediaAdmin/inner_row_media.html.twig", outer_list_rows_mosaic : "@@SonataMedia/MediaAdmin/list_outer_rows_mosaic.html.twig", base_list_field : "@@SonataAdmin/CRUD/base_list_flat_field.html.twig", list : "@@SonataMedia/MediaAdmin/list.html.twig", edit : "@@SonataMedia/MediaAdmin/edit.html.twig" ] ]

While the new field ("language") loads on my admin screen in the CMS, I find that I now have only half of the fields! The "preview" tab is entirely missing. The fields from the "media" tab are present, but the tab is now labeled as "pages."

Any ideas about what might be going on here?


Solution

  • It turns out that I didn't have to go through the whole baroque dance of redeclaring the service with all dependencies. Instead, all I needed to do in services.yaml was to create a new parameter key pointing at my custom class:

    parameters:
        locale: 'de'
        ...
        sonata.media.admin.media.class: 'App\Application\Sonata\MediaBundle\Admin\ORM\MediaAdmin'
    

    After that, everything worked perfectly. Boffo!