3

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?

  • I'd like to help, but I [couldn't install Sonata](https://github.com/sonata-project/sandbox/issues/1206) to give it a try. Do you have a public repository where I can reproduce this issue? – Stephan Vierkant Jul 26 '21 at 10:04

1 Answers1

-1

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!