drskullster
drskullster

Reputation: 831

Set a translation domain on a form created without a class

I'm trying to create a form with translated labels. I'm not using an AbstractType class, I just want to declare my form in a controller :

$form = $this->createFormBuilder($user)
             ->add('website', 'url', array(
                 'required' => false,
                 'label' => 'profession.website.label'
             ));

How can I add a translation domain to my form ?

Upvotes: 2

Views: 253

Answers (1)

Chase
Chase

Reputation: 9362

I believe you pass it as an array to the 2rd argument for createFormBuilder

$form = $this->createFormBuilder($user, [
    'translation_domain' => 'comment'
])->add('website', 'url', [
    'required' => false,
    'label' => 'profession.website.label'
]);

First argument is the data for the form, the second is the options. http://api.symfony.com/2.0/Symfony/Bundle/FrameworkBundle/Controller/Controller.html#method_createFormBuilder

Upvotes: 4

Related Questions