I created a custom entity "Faq" with their routes . When I make a dump of "faqs" in my index.html.twig Faq#translations#collection is empty.
I need a "question"and a "response" in the collection. In my database all fields are present in FaqTranslation.
What I've could missed?
Sorry for my poor English.
Thanks .
result dump(faqs)
Faq {#3359 ▼
-id: 2
#translations: PersistentCollection {#3369 ▼
-snapshot: []
-owner: Faq {#3359}
-association: array:16 [ …16]
-em: EntityManager {#2123 …11}
-backRefFieldName: "translatable"
-typeClass: ClassMetadata {#3361 …}
-isDirty: false
#collection: ArrayCollection {#3371 ▼
-elements: []
}
#initialized: false
}
#translationsCache: []
#currentLocale: "fr_FR"
#currentTranslation: null
#fallbackLocale: "en_US"
}
Faq Entity
<?php
namespace AppBundle\Entity;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Model\TranslatableInterface;
use Sylius\Component\Resource\Model\TranslatableTrait;
/**
* Faq
*/
class Faq implements ResourceInterface, TranslatableInterface
{
use TranslatableTrait {
__construct as private initializeTranslationsCollection;
}
public function __construct()
{
$this->initializeTranslationsCollection();
}
/**
* @var int
*/
private $id;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set response
*
* @param string $response
*
* @return FaqTranslation
*/
public function setResponse($response)
{
return $this->getTranslation()->setResponse($response);
}
/**
* Get response
*
* @return string
*/
public function getResponse()
{
return $this->getTranslation()->getResponse();
}
/**
* Set question
*
* @param string $question
*
* @return FaqTranslation
*/
public function setQuestion($question)
{
return $this->getTranslation()->setQuestion($question);
}
/**
* Get question
*
* @return string
*/
public function getQuestion()
{
return $this->getTranslation()->getQuestion();
}
/**
* Set locale
*
* @param string $locale
*
* @return FaqTranslation
*/
public function setLocale($locale)
{
return $this->getTranslation()->setLocale($locale);
}
/**
* Get locale
*
* @return string $locale
*/
public function getLocale()
{
return $this->getTranslation()->getLocale();
}
/**
* {@inheritdoc}
*/
protected function createTranslation()
{
return new FaqTranslation();
}
}
FaqTranslation Entity
<?php
namespace AppBundle\Entity;
use Sylius\Component\Resource\Model\AbstractTranslation;
use Sylius\Component\Resource\Model\ResourceInterface;
/**
* FaqTranslation
*/
class FaqTranslation extends AbstractTranslation implements ResourceInterface
{
/**
* @var int
*/
private $id;
/**
* @var string
*/
private $response;
/**
* @var string
*/
private $question;
protected $locale;
/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Set response
*
* @param string $response
*
* @return FaqTranslation
*/
public function setResponse($response)
{
$this->response = $response;
return $this;
}
/**
* Get response
*
* @return string
*/
public function getResponse()
{
return $this->response;
}
/**
* Set question
*
* @param string $question
*
* @return FaqTranslation
*/
public function setQuestion($question)
{
$this->question = $question;
return $this;
}
/**
* Get question
*
* @return string
*/
public function getQuestion()
{
return $this->question;
}
/**
* Set locale
*
* @param string $locale
*
* @return FaqTranslation
*/
public function setLocale($locale)
{
$this->locale = $locale;
return $this;
}
/**
* Get locale
*
* @return string $locale
*/
public function getLocale()
{
return $this->locale;
}
}
views/Faq/index.html.twig
{% extends '@SyliusShop/layout.html.twig' %}
{% block content %}
{{ dump(faqs.translations.toArray)}}
{% endblock %}