简体   繁体   English

Symfony 2.8:编辑服务配置

[英]Symfony 2.8 : Edit service config

I'm trying to edit or override the config (admin_orm.xml) of a service (sonata.user.admin.user) which is created by SonataUserBundle. 我正在尝试编辑或覆盖由SonataUserBundle创建的服务(sonata.user.admin.user)的配置(admin_orm.xml)。 I'd like to be able to use the entitymanager in that service. 我希望能够在该服务中使用entitymanager。 Because i need to edit edit on another entity after the creation of a new user on SonataAdminBundle ( https://sonata-project.org/bundles/admin/2-3/doc/reference/saving_hooks.html ). 因为我需要在SonataAdminBundle上创建新用户后编辑另一个实体的编辑( https://sonata-project.org/bundles/admin/2-3/doc/reference/saving_hooks.html )。

The config file: 配置文件:

<parameters>
    <parameter key="sonata.user.admin.groupname">sonata_user</parameter>
</parameters>

<services>
    <service id="sonata.user.admin.user" class="%sonata.user.admin.user.class%">
        <tag name="sonata.admin" manager_type="orm" group="%sonata.user.admin.groupname%" label="users" label_catalogue="SonataUserBundle" label_translator_strategy="sonata.admin.label.strategy.underscore" />
        <argument />
        <argument>%sonata.user.admin.user.entity%</argument>
        <argument>%sonata.user.admin.user.controller%</argument>
        <call method="setUserManager">
            <argument type="service" id="fos_user.user_manager" />
        </call>
        <call method="setTranslationDomain">
            <argument>%sonata.user.admin.user.translation_domain%</argument>
        </call>
    </service>

    <service id="sonata.user.admin.group" class="%sonata.user.admin.group.class%">
        <tag name="sonata.admin" manager_type="orm" group="%sonata.user.admin.groupname%" label="groups" label_catalogue="SonataUserBundle"  label_translator_strategy="sonata.admin.label.strategy.underscore" />
        <argument />
        <argument>%sonata.user.admin.group.entity%</argument>
        <argument>%sonata.user.admin.group.controller%</argument>
        <call method="setTranslationDomain">
            <argument>%sonata.user.admin.group.translation_domain%</argument>
        </call>
    </service>
</services>

I think you sound copy the service Definition and deactivate the boxed fosuserbundle service. 我认为你声音复制服务定义并停用盒装的fosuserbundle服务。

To omit Code duplications you could extend from the original service. 要省略代码重复,您可以从原始服务扩展。

Define the menu entries in your config.yml to exclude the native admin Services. 在config.yml中定义菜单条目以排除本机管理服务。

I found a way to fix my problem which is this line: 我找到了解决问题的方法,这就是这一行:

$em = $this->getConfigurationPool()->getContainer()->get('doctrine.orm.entity_manager');

it's probably not the cleanest way to fix the problem, but it works for me. 它可能不是解决问题最简洁的方法,但它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM