Symfony2: YAML to expose a service inside SonataAdminBundle

The documentation for the SonataAdminBundle mentions how to expose services inside your Admin class using XML:

<service id="sonata.news.admin.post" class="%sonata.news.admin.post.class%">
    <tag name="sonata.admin" manager_type="orm" group="sonata_blog" label="post"/>
    <argument />
    <argument>%sonata.news.admin.post.entity%</argument>
    <argument>%sonata.news.admin.post.controller%</argument>

    <call method="setUserManager">
        <argument type="service" id="fos_user.user_manager" />
    </call>

</service>

But unfortunately it doesn’t detail how to do it YAML. Turns out its pretty straightforward, the “gotcha” of course being you need to add the “@” to indicate a service:

ct.be.admin.users:
  class: CT\BEBundle\Admin\UserAdmin
  tags:
	- { name: sonata.admin, manager_type: orm, group: Manage User Settings, label: Users }
  arguments: [null, CT\BEBundle\Entity\User, "SonataAdminBundle:CRUD"]
  calls:
	- [setUserManager, [@fos_user.user_manager]]

Questions or comments about this? Email us at contact@setfive.com.

Read more