Symfony 2, MongoDB + a2lix / translation-form-bundle
I have a problem with the "a2lix / translation-form-bundle" when using MongoDB in Symfony 2.5. I think I did everything as in the documentation, but I have "Missing required parameter" class " .
My product:
/**
* Class Product
* @MongoDB\Document(repositoryClass="MyBundle\ProductBundle\Repository\ProductRepository")
* @Gedmo\TranslationEntity(class="MyBundle\ProductBundle\Document\ProductTranslation")
*/
class Product implements Translatable
{
/**
* @MongoDB\Id
*
*/
protected $id;
/**
* @MongoDB\String
* @Gedmo\Translatable
*/
protected $name;
/**
*
* @MongoDB\ReferenceMany(targetDocument="MyBundle\ProductBundle\Document \ProductTranslation", mappedBy="object", cascade={"all"})
*
*/
private $translations;
public function __construct()
{
$this->translations = new ArrayCollection();
}
public function __toString()
{
return $this->getName();
}
/**
* Get id
*
* @return id $id
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
* @return self
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string $name
*/
public function getName()
{
return $this->name;
}
/**
* Set translations
*
* @param ArrayCollection $translations
* @return Product
*/
public function setTranslations($translations)
{
foreach ($translations as $translation) {
$translation->setObject($this);
}
$this->translations = $translations;
return $this;
}
/**
* Get translations
*
* @return ArrayCollection
*/
public function getTranslations()
{
return $this->translations;
}
And this is my ProductTranslation:
class ProductTranslation extends AbstractPersonalTranslation
{
/**
* @MongoDB\ReferenceOne(targetDocument="MyBundle\ProductBundle\Document\Product", inversedBy="translations")
*
*/
public $object;
}
I am still getting this one . The required class option is missing. " error and I don't know what the problem is.
source to share
You are getting this error because MongoDB ODM Mapping creates a mapping of fields in the Reference.
For example, if you have a ManyToOne or OneToMany relationship, the ORM does not create a field mapping.
So a2lix sees your field object
as a normal display field. Since the form builder allows this object
type field document
, so you need to provide a parameter class
for it to work.
But if you provide this option then your field object
will show up as a translatable field and that definitely sucks.
So try this:
->add('translations', 'a2lix_translations', [
'exclude_fields' => [
'object',
]
])
This will help you fix this problem.
source to share