No mapping file found when implementing TranslationInterface

  doctrine, php, sonata, symfony, translation

I am using Ez-Extends to extend the Sonata Classification Bundle’s Category entity.

Now I want to use the KnpDoctrineBehaviorsModelTranslatableTranslatableTrait to make my Category translatable. I apply the trait in my Category class and have it implement TranslatableInterface. Then I create a new CategoryTranslation class:

<?php

namespace AppApplicationSonataClassificationBundleEntity;

use DoctrineORMMapping as ORM;
use KnpDoctrineBehaviorsContractEntityTranslationInterface;
use KnpDoctrineBehaviorsModelTranslatableTranslationTrait;
use SymfonyComponentSerializerAnnotationGroups;

/**
 * @ORMEntity
 */
class CategoryTranslation implements TranslationInterface
{
    use TranslationTrait;

    /**
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     * @ORMColumn(type="integer")
     */
    private $id;

    /**
     * @var string | null
     * @ORMColumn(type="string")
     * @Groups("filter")
     */
    private $name;

    private $trans;

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param mixed $id
     * @return CategoryTranslation
     */
    public function setId($id)
    {
        $this->id = $id;
        return $this;
    }

    /**
     * @return string|null
     */
    public function getName(): ?string
    {
        return $this->name;
    }

    /**
     * @param string|null $name
     * @return CategoryTranslation
     */
    public function setName(?string $name): CategoryTranslation
    {
        $this->name = $name;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getTrans()
    {
        return $this->trans;
    }

    /**
     * @param mixed $trans
     * @return CategoryTranslation
     */
    public function setTrans($trans)
    {
        $this->trans = $trans;
        return $this;
    }



}

However, when I try to do anything in the app, I now get this message:

In MappingException.php line 65:

  No mapping file found named 'CategoryTranslation.orm.xml' for class 'AppApplicationSonataClassificationBundleE
  ntityCategoryTranslation'.

As far as I know, this new entity should be using annotations for mapping, not XML. What am I doing wrong?

Source: Ask PHP

LEAVE A COMMENT