Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to overwrite FOS user bundle form labels

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?

like image 953
Bartosz Rychlicki Avatar asked Nov 20 '12 12:11

Bartosz Rychlicki


2 Answers

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

like image 93
AlterPHP Avatar answered Nov 07 '22 05:11

AlterPHP


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(),
        ...
    ];
...
}
like image 35
Jibato Avatar answered Nov 07 '22 04:11

Jibato