1
votes

In Sonata Admin I would like to translate entity fields. For that I use “Personal translations” from GedmoDoctrineExtension (v2.4.10). For example, I have entity “Post” with translatable field “content” and appropriate translation entity – “PostTranslation”. “Post” is located in “Entity” directory, but “PostTranslation” – in “Entity/Translation”. Everything work fine. In order to have form for entity translation in Admin page, I use a2lix/TranslationFormBundle (v2.0). And I receive following error:

Class AppBundle\Entity\PostTranslation does not exist

list($namespaceAlias, $simpleClassName) = explode(':', $class, 2);
$class = $this->getAliasNamespace($namespaceAlias) .'\\'. $simpleClassName;
}
$proxyClass = new \ReflectionClass($class); // Exception is thrown here!
if ($proxyClass->implementsInterface($this->proxyInterfaceName)) {
if (! $parentClass = $proxyClass->getParentClass()) {
return null;

It seems, that bundle by default search translation class in “Entity” directory, but I need in “Entity/Translation”. How can I achieve such behavior?

1

1 Answers

0
votes

You need to provide for every translatable entity a method named either getTranslationEntityClass or getTranslationClass and this must be static.

namespace AppBundle\Entity;

class Post
{
    //...

    /**
     * @return string
     */
    public static function getTranslationClass()
    {
        return __NAMESPACE__ . '\\Translation\\Post';
    }
}