I am trying to build forms for translatable entities but i get 4 form fields that i don't want.
It seems these fields are coming from the Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation but i wonder what i need to do with these fields ?
Is it normal that they are appearing in the translation form ?
If someone have usefull examples that would be great.
- It's a Symfony2 project.
- Doctrine extensions are installed with stof: https://github.com/stof/StofDoctrineExtensionsBundle/
- Aj2lix TranslationFormBundle: https://github.com/a2lix/TranslationFormBundle
Please find below the following files:
- Page.php (this is the main entity)
- PageTranslation.php (the translation entity)
Page.php
<?php
namespace Syms\PageBundle\Entity;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Page
*
* @Gedmo\Tree(type="nested")
* @ORM\Table(name="syms_page")
* @ORM\Entity(repositoryClass="Syms\PageBundle\Entity\PageRepository")
*/
class Page
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var boolean
*
* @ORM\Column(name="is_active", type="boolean", nullable=false, options={"default":0})
*/
private $isActive;
/**
* @var boolean
*
* @ORM\Column(name="is_homepage", type="boolean", nullable=false, options={"default":0})
*/
private $isHomepage;
/**
* @var \DateTime
*
* @Gedmo\Timestampable(on="create")
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
protected $translations;
/**
* @Gedmo\TreeLeft
* @ORM\Column(name="lft", type="integer")
*/
private $lft;
/**
* @Gedmo\TreeRight
* @ORM\Column(name="rgt", type="integer")
*/
private $rgt;
/**
* @Gedmo\TreeLevel
* @ORM\Column(name="lvl", type="integer")
*/
private $lvl;
/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="Page", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* @Gedmo\TreeRoot
* @ORM\Column(name="root", type="integer", nullable=true)
*/
private $root;
/**
* @ORM\OneToMany(targetEntity="Page", mappedBy="parent")
* @ORM\OrderBy({"lft" = "ASC"})
*/
private $children;
/**
* Required for Translatable behaviour
* @Gedmo\Locale
*/
protected $locale;
/**
* Constructor
*/
public function __construct()
{
$this->children = new ArrayCollection();
$this->translations = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set isActive
*
* @param boolean $isActive
* @return Page
*/
public function setIsActive($isActive)
{
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive()
{
return $this->isActive;
}
/**
* Set isHomepage
*
* @param boolean $isHomepage
* @return Page
*/
public function setIsHomepage($isHomepage)
{
$this->isHomepage = $isHomepage;
return $this;
}
/**
* Get isHomepage
*
* @return boolean
*/
public function getIsHomepage()
{
return $this->isHomepage;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
* @return Page
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
public function setParent(Page $parent)
{
$this->parent = $parent;
}
public function getParent()
{
return $this->parent;
}
/**
* Set lft
*
* @param integer $lft
* @return Page
*/
public function setLft($lft)
{
$this->lft = $lft;
return $this;
}
/**
* Get lft
*
* @return integer
*/
public function getLft()
{
return $this->lft;
}
/**
* Set rgt
*
* @param integer $rgt
* @return Page
*/
public function setRgt($rgt)
{
$this->rgt = $rgt;
return $this;
}
/**
* Get rgt
*
* @return integer
*/
public function getRgt()
{
return $this->rgt;
}
/**
* Set lvl
*
* @param integer $lvl
* @return Page
*/
public function setLvl($lvl)
{
$this->lvl = $lvl;
return $this;
}
/**
* Get lvl
*
* @return integer
*/
public function getLvl()
{
return $this->lvl;
}
/**
* Set root
*
* @param integer $root
* @return Page
*/
public function setRoot($root)
{
$this->root = $root;
return $this;
}
/**
* Get root
*
* @return integer
*/
public function getRoot()
{
return $this->root;
}
/**
* Add children
*
* @param \Syms\PageBundle\Entity\Page $children
* @return Page
*/
public function addChild(Page $children)
{
$this->children[] = $children;
return $this;
}
/**
* Remove children
*
* @param \Syms\PageBundle\Entity\Page $children
*/
public function removeChild(Page $children)
{
$this->children->removeElement($children);
}
/**
* Get children
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
public function getTranslations()
{
return $this->translations;
}
public function addTranslation(PageTranslation $t)
{
$this->translations->add($t);
$t->setObject($this);
}
public function removeTranslation(PageTranslation $t)
{
$this->translations->removeElement($t);
}
public function setTranslations($translations)
{
$this->translations = $translations;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
}
}
PageTranslation.php
<?php
namespace Syms\PageBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractTranslation;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Table(name="ext_translations_page", indexes={
* @ORM\Index(name="page_translation_idx", columns={"locale", "object_class", "field", "foreign_key"})
* })
* @ORM\Entity(repositoryClass="Gedmo\Translatable\Entity\Repository\TranslationRepository")
*/
class PageTranslation extends AbstractTranslation
{
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(name="title", type="string", length=255)
*/
private $title;
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(name="meta_title", type="string", length=255)
*/
private $metaTitle;
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(name="meta_keywords", type="text", nullable=true)
*/
private $metaKeywords;
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(name="meta_description", type="text", nullable=true)
*/
private $metaDescription;
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(name="url_key", type="string", length=255)
*/
private $urlKey;
/**
* Set title
*
* @param string $title
* @return PageTranslation
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* Set metaTitle
*
* @param string $metaTitle
* @return PageTranslation
*/
public function setMetaTitle($metaTitle)
{
$this->metaTitle = $metaTitle;
return $this;
}
/**
* Get metaTitle
*
* @return string
*/
public function getMetaTitle()
{
return $this->metaTitle;
}
/**
* Set metaKeywords
*
* @param string $metaKeywords
* @return PageTranslation
*/
public function setMetaKeywords($metaKeywords)
{
$this->metaKeywords = $metaKeywords;
return $this;
}
/**
* Get metaKeywords
*
* @return string
*/
public function getMetaKeywords()
{
return $this->metaKeywords;
}
/**
* Set metaDescription
*
* @param string $metaDescription
* @return PageTranslation
*/
public function setMetaDescription($metaDescription)
{
$this->metaDescription = $metaDescription;
return $this;
}
/**
* Get metaDescription
*
* @return string
*/
public function getMetaDescription()
{
return $this->metaDescription;
}
/**
* Set urlKey
*
* @param string $urlKey
* @return PageTranslation
*/
public function setUrlKey($urlKey)
{
$this->urlKey = $urlKey;
return $this;
}
/**
* Get urlKey
*
* @return string
*/
public function getUrlKey()
{
return $this->urlKey;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}