I have Entity in my app, which has 2 translatable fields, using Doctrine Translatable Extension:
class Page implements Translatable
{
/......
/**
* @var string $name
* @Gedmo\Translatable
* @ORM\Column(name="name", type="string", length=255)
*/
private $name;
/**
* @var text $content
* @Gedmo\Translatable
* @ORM\Column(name="content", 开发者_Python百科type="text")
*/
private $content;
/........
}
I use one table for multiple entities translations. Now i would like to use one form to get the original and translated (to 1 language) values for these attributes, so it should have 4 fields.
I've defined new form derivating from AbstractType and tried to add those 2 fields using FormBuilder, but it says that their corresponding entities do not contain these fields. I've tried to add these fields to entities, and declare getters for them, but the only way i know to get translations for entities is to use dedicated entity manager and AFAIK providing entity manager access to entity isn't good practice.
Is there a way to use forms to handle such thing?
I know it's an old question, but anyway.
You could put the fields for translated content using FormBuilder with attribute:
array('mapped'=>false)
Take the data like this:
$form->get('field_name')->getData();
and then persist it like this
https://github.com/l3pp4rd/DoctrineExtensions/blob/master/doc/translatable.md#multi-translations
I hope it helps somebody.
精彩评论