顯示它%name% (%capacity% places)
只是一個「可能」表示在表單視圖,所以我會這樣非常具體的表現轉移到你的表單類型。
什麼可以在地點的__toString()
方法屬於實體:使用choice_label
my_translation: %name% (%capacity% places)
下一頁您表單類型(也:
class Venue
{
private $name;
... setter & getter method
public function __toString()
{
return $this->getName();
}
}
messages.en.yml值得了解:choice_translation_domain):
use Symfony\Component\Translation\TranslatorInterface;
class YourFormType 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(
'venue',
EntityType::class,
array(
'choice_label' => function (Venue $venue, $key, $index) {
// Translatable choice labels
return $this->translator->trans('my_translation', array(
'%name%' => $venue->getName(),
'%capacity%' => $venue->getCapacity(),
));
}
)
);
}
}
&也註冊表單類型的服務services.yml:
your_form_type:
class: Your\Bundle\Namespace\Form\YourFormType
arguments: ["@translator"]
tags:
- { name: form.type }
而這種進入EasyAdmin怎麼樣? – rishta