1

I'm using Symfony 3.4 and knp doctrine behaviors for translation.

My entity Article looks like:

<?php
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;

/**
 * Article
 *
 * @ORM\Table(name="article")
 * @ORM\Entity(repositoryClass="AppBundle\Repository\ArticleRepository")
 */
class Article
{
    use ORMBehaviors\Translatable\Translatable;
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
//...
}

Then I have entity ArticleTranslation

<?php
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;

/**
 * @ORM\Entity
 */
class ArticleTranslation
{
    use ORMBehaviors\Translatable\Translation;

    /**
     * @ORM\Column(type="string", length=128)
     */
    protected $headline;

//...
}

Now my app throws me an error:

Unable to find the association target class of "headline" in AppBundle\Entity\Article.

It expects a relation between Article and ArticleTranslation. There is a sentence in the documentation:

The default naming convention (or its customization via trait methods) avoids you to manually handle entity associations. It is handled automatically by the TranslationSubscriber.

Why does this happen? What am I missing?

edit

bin/console doctrine:schema:update

 [OK] Nothing to update - your database is already in sync with the current entity metadata.

bin/console debug:config knp_doctrine_behaviors

knp_doctrine_behaviors:
    translatable: true
    blameable: false
    geocodable: false
    loggable: false
    sluggable: false
    soft_deletable: false
    sortable: false
    timestampable: false
    tree: false

I'm using this in sonata admin, with a2lix translatable.

ArticleAdmin.php:

<?php
namespace AppBundle\Admin;

use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use A2lix\TranslationFormBundle\Form\Type\TranslationsType;

final class ArticleAdmin extends AbstractAdmin
{
    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('headline', TranslationsType::class);
    }

    //...
}
repincln
  • 2,029
  • 5
  • 24
  • 34
  • 1
    This looks fine to me. Did you update your schema? What do you get when you run `bin/console doctrine:schema:update`? Are you sure the translatable behaviour is enabled? Does it show `true` when you run `bin/console debug:config knp_doctrine_behaviors`? – dbrumann Feb 04 '19 at 08:49
  • @dbrumann: I edited my question. It seems fine to me also ... i don't get it – repincln Feb 04 '19 at 08:59
  • try to clear the cache – Majesty Feb 04 '19 at 11:56

1 Answers1

0

Try to use

$formMapper->add('translations', TranslationsType::class);

I had the same problem. Probably the field name needs to be exactly translations.

AddeusExMachina
  • 592
  • 1
  • 11
  • 22