Using Sonata's Easy Extends tool, I am extending the MediaAdmin base class and overriding the existing service for that class. In doing so, I've converted this XML service definition (in the vendor folder):
<service id="sonata.media.admin.media" class="%sonata.media.admin.media.class%" public="true">
<tag name="sonata.admin" manager_type="orm" group="%sonata.media.admin.groupname%" label_catalogue="%sonata.media.admin.media.translation_domain%" label="media" label_translator_strategy="sonata.admin.label.strategy.underscore" icon="%sonata.media.admin.groupicon%"/>
<argument/>
<argument>%sonata.media.admin.media.entity%</argument>
<argument>%sonata.media.admin.media.controller%</argument>
<argument type="service" id="sonata.media.pool"/>
<argument type="service" id="sonata.media.manager.category" on-invalid="null"/>
<call method="setModelManager">
<argument type="service" id="sonata.media.admin.media.manager"/>
</call>
<call method="setTranslationDomain">
<argument>%sonata.media.admin.media.translation_domain%</argument>
</call>
<call method="setTemplates">
<argument type="collection">
<argument key="inner_list_row">@SonataMedia/MediaAdmin/inner_row_media.html.twig</argument>
<argument key="outer_list_rows_mosaic">@SonataMedia/MediaAdmin/list_outer_rows_mosaic.html.twig</argument>
<argument key="base_list_field">@SonataAdmin/CRUD/base_list_flat_field.html.twig</argument>
<argument key="list">@SonataMedia/MediaAdmin/list.html.twig</argument>
<argument key="edit">@SonataMedia/MediaAdmin/edit.html.twig</argument>
</argument>
</call>
</service>
... into this yaml:
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" ] ]
The yaml parses just fine when I try running a cache warmup. The problem, however, is that I now get this error message:
The service "sonata.media.admin.media.template_registry" has a dependency on a non-existent service "SonataMedia/MediaAdmin/inner_row_media.html.twig".
This seems strange to me, since the version of the admin service definition in the vendor folder (which was working fine before I overrode it) also has this same dependency. Any ideas about what's going wrong, and what I can do to fix it?
The @
sign in a definition typically tells the compiler to look for a service with that name. If you are using it as a template namespace you will probably have to escape the symbol. Try this:
<call method="setTemplates">
<argument type="collection">
<argument key="inner_list_row">@@SonataMedia/MediaAdmin/inner_row_media.html.twig</argument>
<argument key="outer_list_rows_mosaic">@@SonataMedia/MediaAdmin/list_outer_rows_mosaic.html.twig</argument>
<argument key="base_list_field">@@SonataAdmin/CRUD/base_list_flat_field.html.twig</argument>
<argument key="list">@@SonataMedia/MediaAdmin/list.html.twig</argument>
<argument key="edit">@@SonataMedia/MediaAdmin/edit.html.twig</argument>
</argument>
</call>