Define translatable entities - MrAPPs-RSM/MrappsBackendBundle GitHub Wiki

Translations

When an entity is translatable, all translatable fields should stay in a separated entity.

for example Product entity, should have its own ProductLang entity that will contains all translations for the unique Product.

Create translation

Add this relation to the entity "ENTITY_NAME".

use Mrapps\BackendBundle\Entity\TranslatedEntity;

class ENTITY_NAME
    extends TranslatedEntity
{
    /**
     * @ORM\OneToMany(targetEntity="ENTITY_NAMELang", mappedBy="padre")
     */
    protected $traduzioni;
}

Define translation class

use Mrapps\BackendBundle\Entity\LanguageBase;

/**
 * @ORM\Table(name="ENTITY_NAME_lang")
 * @ORM\Entity()
 */
class ENTITY_NAMELang
    extends LanguageBase;
{
    /**
     * @ORM\ManyToOne(targetEntity="ENTITY_NAME", inversedBy="traduzioni")
     * @ORM\JoinColumn(name="padre_id", referencedColumnName="id")
     */
    private $padre;

    public function setPadre(ENTITY_NAME $father)
    {
        $this->padre = $father;
    }
}

TranslatedEntity abstract class

This class aims to provide a public method TranslatedEntity::hasTranslations() that inform developer if current entity has or not translations in database. In case of missing translations, an exception will be thrown.