I can´t concatenate a label with string.
->add('originador', EntityType::class, array(
'label' => "app.label.x_originador".'*',
'class' => 'AppBundle:Usuario',
'em' => $options['entityManager'],
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u');
},
'placeholder' => '',
'required' => false,
))
In the part of 'label' => "app.label.x_originador".'*',
I need that the result be Originador*
,because the label is for required value.
The result that I recieve is app.label.x_originador*
Please, help me to get
Originador*
as result.
You can pass the translator service to your form type and translate then concatenate like this:
class MyFormType extends AbstractType { private $translator; public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('originador', EntityType::class, array( 'label' => $this->translator->trans('app.label.x_originador',[], 'domain').'*', 'class' => 'AppBundle:Usuario', 'em' => $options['entityManager'], 'query_builder' => function (EntityRepository $er) { return $er->createQueryBuilder('u'); }, 'placeholder' => '', 'required' => false, )); } }
juste replace "domain" with your translation domain.
EDIT: but yeah, the best solution is probably @ccKep's one