A2lix Translation Form Bundle を使用して、エンティティのデータベース翻訳を実現しています。次のようなエンティティ ページを作成します。
class Page
{
/**
* Must define for translating this entity
*/
use ORMBehaviors\Translatable\Translatable;
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
}
「PageTranslation」エンティティも作成します。
class PageTranslation
{
use ORMBehaviors\Translatable\Translation;
/**
* @ORM\Column(type="string", length=25)
*/
protected $title;
}
「PageType」の形式で、翻訳を含めます。
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('translations', 'a2lix_translations', array(
'fields' => array(
'title' => array(
'label' => 'pageTitle',
'field_type' => 'text',
'attr' => array()
)
)
));
}
/**
* Define mapper for this form
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'App\MyBundle\Entity\Page',
'cascade_validation' => true,
));
}
「PageTranslation」エンティティで定義されている title 属性を検証したいと思います。
App\MyBundle\Entity\Page:
properties:
translations:
- Valid: ~
App\MyBundle\Entity\PageTranslation:
properties:
title:
- NotBlank: ~
- Length:
max: 255
しかし、空のタイトルでフォームを送信すると、検証は値「TRUE」として返されます。誰かが私の問題のヒントを教えてくれますか?