Skip to content

Instantly share code, notes, and snippets.

@ricbra
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricbra/437bc22397efa638d4fa to your computer and use it in GitHub Desktop.
Save ricbra/437bc22397efa638d4fa to your computer and use it in GitHub Desktop.
Translate Entity field labels
<?php
namespace Bkv\Bundle\LbwBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Validator\Constraints\NotBlank;
class CategoryType extends AbstractType
{
/**
* @var Translator
*/
private $translator;
public function __construct(Translator $translator)
{
$this->translator = $translator;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$translator = $this->translator;
$builder
->add('category', 'entity', [
'label' => 'Choose a category',
'class' => 'Model:Category',
'expanded' => true,
// The solution
'choice_translation_domain' => true,
])
}
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
public function getName()
{
return 'bkv_lbw_category';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment