Last active
August 29, 2015 14:27
-
-
Save ricbra/437bc22397efa638d4fa to your computer and use it in GitHub Desktop.
Translate Entity field labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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