TranslationFormBundle
TranslationFormBundle copied to clipboard
Trying to use a2lix/TranslationFormBundle with #[Gedmo\Translatable]
Sorry to post here, I don't think is a bug, however I am not finding a way make it work
’m currently facing an issue with translating certain fields in my form. The error I’m encountering is:
Field 'name' doesn't exist in App\Entity\ModuleTranslation
It appears that the system is expecting a 'name' field in the ModuleTranslation class. However, this field does not exist in our translation entity; we only have a reference to the field in the database.
Any clues that could help me?
ModuleClass: `
#[Gedmo\TranslationEntity(class: ModuleTranslation::class)] class Module implements Translatable { use TimestampableEntity;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(name: 'id', type: 'integer')]
private $id;
#[ORM\Column(name: 'name', type: 'string', length: "255")]
#[Assert\NotBlank]
#[Gedmo\Translatable]
protected $name;
#[ORM\Column(name: 'description', type: 'string', length: "255", nullable:true)]
#[Assert\NotBlank]
#[Gedmo\Translatable]
protected $description;
#[ORM\Column(name: 'active', type: 'boolean')]
#[Gedmo\Translatable]
protected $active;
#[ORM\Column(name: 'module_order', type: 'integer')]
private $order;
#[ORM\Column(name: 'module_type', type: 'string', length: 255)]
#[Assert\NotBlank]
private $type;
`
ModuleTranslationClass:
` class ModuleTranslation extends AbstractPersonalTranslation {
public function __construct($locale, $field, $value)
{
$this->setLocale($locale);
$this->setField($field);
$this->setContent($value);
}
#[ORM\ManyToOne(targetEntity: Module::class, inversedBy: 'translations')]
#[ORM\JoinColumn(name: 'object_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected $object;
} `
Form:
` class ModuleForm extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('translations', TranslationsType::class, [
'fields' => [
'name' => [
'field_type' => 'text',
'label' => 'name.',
'locale_options' => [
'en' => ['label' => 'Name'],
'pt' => ['label' => 'Nome'],
],
'attr' => [
'class' => 'form-control',
'placeholder' => '',
]
],
'description' => [
'field_type' => 'text',
'label' => 'description.',
'locale_options' => [
'en' => ['label' => 'Description'],
'pt' => ['label' => 'Descrição'],
],
'attr' => [
'class' => 'form-control',
'placeholder' => '',
]
],
'active' => [
'field_type' => 'choice',
'label' => 'name.',
'locale_options' => [
'en' => ['label' => 'Name'],
'pt' => ['label' => 'Nome'],
],
'attr' => [
'class' => 'form-control kt-radio-inline',
],
'multiple' => false,
'expanded' => true,
'choices' => ModuleType::$activesAvailable,
'required' => true
],
],
'locale_labels' => [
'pt' => 'Portuguese',
'en' => 'English',
],
]);
}
} `