如何覆盖FOS用户捆绑的表单标签[英] How to overwrite FOS user bundle form labels

本文是小编为大家收集整理的关于如何覆盖FOS用户捆绑的表单标签的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我很难覆盖Symfony2使用的用户捆绑包.

我已经在覆盖表单类,但是" setoption"等元素没有选择.

我只能删除一个元素,而不仅仅是用适当的标签添加它,但这似乎是过度的.是否有任何不错的方式可以在表单元素上覆盖选项,或者只是翻译键,也许是?

推荐答案

您不需要覆盖表单类.

复制/粘贴vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/translations/FOSUserBundle.xx.yml app/Resources/translations目录中的文件(具有相同的目录结构和相同的文件名),并将翻译重新定义为您的便利.

编辑:正如 @Mario-Johnathan所说的那样,覆盖翻译不是捆绑继承的一部分.请参阅 override.html#translations 用于官方文档

其他推荐答案

已经说过,您可以将翻译文件放入:
app/Resources/translations

但是,如果您将其覆盖在父束(src/MyAppBundle/Resources/translations)或其他任何捆绑包中,请确保在 buge buge 中的捆绑包:

public function registerBundles()
{
    $bundles = [
        ...
        new FOS\UserBundle\FOSUserBundle(),
        new MyAppBundle\MyAppBundle(),
        ...
    ];
...
}

本文地址:https://www.itbaoku.cn/post/2090763.html

问题描述

I have a hard time overwriting labels that the FOS user bundle for Symfony2 uses.

I'm already overwriting the Form class, but there is no option for elements like "setOption", only getters.

I could just remove an element and than add it again with the proper label but this seems like an overkill. Is there any nice way of overwriting options on form elements, or just translation keys, perhaps?

推荐答案

You don't need to overwrite Form classes.

Copy/paste vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/translations/FOSUserBundle.xx.yml files in your app/Resources/translations directory (with the same directory structure and the same file name) and redefine translations to your convenience.

edit: As told by @mario-johnathan, overriding translations is not part of bundle inheritance. See http://symfony.com/doc/current/cookbook/bundles/override.html#translations for official documentation

其他推荐答案

As already said you can put your translations files in :
app/Resources/translations

But if you override it in your parent bundle (src/MyAppBundle/Resources/translations) or in any other bundle, make sure to load your bundle after the overridden bundle in your Kernel :

public function registerBundles()
{
    $bundles = [
        ...
        new FOS\UserBundle\FOSUserBundle(),
        new MyAppBundle\MyAppBundle(),
        ...
    ];
...
}