I have 2 entities Category and Criteria, the relation between category and criteria is an OneToMany (bidirectional relation). Without translation I don't have any problems for manage the form (CategoryType and CriteriaType), etc.
Category and Criteria contains a "libelle" attribute and I would like translate those attributes in English and in another language, so I have something like:
// Category entity :
/**
* @ORM\Column(name="libelle", type="string", length=255)
* @Gedmo\Translatable
*/
private $libelle; // can't be blank
// other attributes
// --------
// Criteria entity :
/**
* @ORM\Column(name="libelle", type="string", length=255)
* @Gedmo\Translatable
*/
private $libelle; // can't be blank
But here, I use GedmoTranslationBundle and A2lix.
Here is my code:
$builder
->add('translations', 'a2lix_translations_gedmo', array(
'translatable_class' => 'Immo\AnnonceBundle\Entity\Category',
'locales' => array('fr', 'en'),
'required' => false,
'fields' => array(
'libelle' => array(
'field_type' => 'text',
'locale_options' => array(
'en' => array(
'label' => 'Libellé du critère (en) :',
'attr' => array('placeholder' => 'Example : Convenience, proximity, etc.')
),
'fr' => array(
'label' => 'Libellé du critère (fr) :',
'attr' => array('placeholder' => 'Exemple : A proximité, commodités, etc.')
)
)
)
'criterias' => array(
'field_type' => 'collection',
'label' => ' ',
'type' => new CriteriaType(),
'allow_add' => true,
'allow_delete' => true
)
)
)
)
CriteriaType :
$builder->add('libelle', 'text', array('libelle' => 'Libellé :'))
My example above, don't work and I don't have any error message it seems $form->isValid() return false and I don't know why.
I don't know how to manage this correctly, can you shed some light on this? Thanks
EDIT : The first error came of missing token, now the $form->isValid() is true and I have this error.
But because of 'translatable_class' => 'Immo\AnnonceBundle\Entity\Category', even the libelle of Critera is an object of Category. Any idea to handle that ? Thanks