How to add label into form builder (not in twig)?
-
28-10-2019 - |
Question
I have this code, but it doesn't work:
$builder->add('name','text',array(
'label' => 'Due Date',
));
the problem i have in fosuserbundle, i have overring form
<?php
namespace Acme\UserBundle\Form\Type;
use Symfony\Component\Form\FormBuilder;
use FOS\UserBundle\Form\Type\RegistrationFormType as BaseType;
class RegistrationFormType extends BaseType
{
public function buildForm(FormBuilder $builder, array $options)
{
// add your custom field
$builder->add('name','text',array(
'label' => 'Due Date',
));
parent::buildForm($builder, $options);
}
public function getName()
{
return 'acme_user_registration';
}
}
but not work, not give me any error and set the label "fos_user_registration_form_name"
Solution
You see label as fos_user_registration_form_name
, because FOSUserBundle
uses translations files to translate all texts in it.
You have to add your translations to file called like Resources/translations/FOSUserBundle.nb.yml
(example for norwegian) or you can modify translations file coming with the bundle (copying it to Acme\UserBundle
is a better way).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow