a2lix / TranslationFormBundle

Ease translations with some dedicated Symfony form types
https://a2lix.fr/bundles/translation-form
MIT License
330 stars 138 forks source link

Compatible with entity that extends another one ? #383

Open cesar-cardinale opened 1 year ago

cesar-cardinale commented 1 year ago

Subject

Is this bundle compatible with child entity that are extending a parent one ?

Like this is my parent class :

#[ORM\MappedSuperclass]
#[ORM\Entity(repositoryClass: WidgetRepository::class)]
#[ORM\InheritanceType("SINGLE_TABLE")]
#[ORM\DiscriminatorColumn(name: "type", type: "string")]
#[ORM\DiscriminatorMap([
    'accordion_vertical_widget' => AccordionVerticalWidget::class,
])]
abstract class Widget implements TranslatableInterface
{
   use TranslatableTrait;
   ...
   private string $title;
   private string $type;
}

And here is my child class :

#[ORM\Entity]
class AccordionVerticalWidget extends Widget implements TranslatableInterface
{
    use TranslatableTrait;
    private string $content;
    ...
}

The problem is that I have just a WidgetCrudController and not a controller for each WidgetType. Then, when I have a field that is only specified for the child and not in the parent, I can't get the auto-generated edit from using the form builder. Because it's said that the parent class (WidgetTranslation) doesn't have the attribute ($content) that I want to set in the child one (AccordionVerticalWidget) of the main class (Widget).

And the parent attributes can be translated, no problem for that.