Я пытаюсь добавить переводы страниц и блоков для Page Bundle. Я не могу найти какую-либо информацию в документации. Может кто-нибудь помочь мне советом по интеграции с TranslationBundle или фрагментом кода?
Моя страница Entity:
<?php
namespace Project\Sonata\PageBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Sonata\PageBundle\Entity\BasePage as BasePage;
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
use Sonata\TranslationBundle\Traits\Gedmo\PersonalTranslatableTrait;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass="Project\AppBundle\Repository\PageRepository")
*/
class Page extends BasePage implements TranslatableInterface
{
use PersonalTranslatableTrait;
/**
* @var int $id
*/
protected $id;
/** @var PageTranslation[]|ArrayCollection */
private $translations;
/**
* Get id.
*
* @return int $id
*/
public function getId()
{
return $this->id;
}
}
Перевод моей сущности:
<?php
namespace Project\Sonata\PageBundle\Entity;
use Sonata\TranslationBundle\Model\Gedmo\AbstractPersonalTranslation;
class PageTranslation extends AbstractPersonalTranslation
{
/**
* Constructor
*
* @param string $locale
* @param string $field
* @param string $content
*/
public function __construct($locale = null, $field = null, $content = null)
{
$this->setLocale($locale);
$this->setField($field);
$this->setContent($content);
}
protected $object;
}
Мой PageBundle / Resources / config / doctrine / Page.orm.xml
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:gedmo="http://Atlantic18.github.io/DoctrineExtensions/schemas/orm/doctrine-extensions-3.0.xsd"
xsi="http://www.w3.org/2001/XMLSchema-instance"
schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity
name="Project\Sonata\PageBundle\Entity\Page"
table="page__page"
repository-class="Project\AppBundle\Repository\PageRepository"
>
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<attribute-overrides>
<attribute-override name="name">
<field column="name">
<gedmo:translatable/>
</field>
</attribute-override>
</attribute-overrides>
<one-to-many field="translations" target-entity="Project\Sonata\PageBundle\Entity\PageTranslation" mapped-by="object" />
<gedmo:translatable field="name"/>
<gedmo:translation entity="Project\Sonata\PageBundle\Entity\PageTranslation" locale="locale"/>
</entity>
</doctrine-mapping>
Мой PageBundle / Resources / config / doctrine / PageTranslation.orm.xml
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xsi="http://www.w3.org/2001/XMLSchema-instance"
schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity
name="Project\Sonata\PageBundle\Entity\PageTranslation"
table="page__page_translations"
>
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<field name="locale" length="8" />
<field name="field" length="32" />
<field name="content" type="text" nullable="true"/>
<many-to-one field="object" target-entity="Project\Sonata\PageBundle\Entity\Page" inversed-by="translations">
<join-column name="object_id" referenced-column-name="id" on-delete="CASCADE" />
</many-to-one>
<unique-constraints>
<unique-constraint columns="locale,object_id,field"></unique-constraint>
</unique-constraints>
</entity>
</doctrine-mapping>
Я начинаю с symfony, поэтому буду благодарен за любую помощь.