I'm just looking the good way to use DoctrineBehaviors by knplabs.
I have allready render a form in sonata admin bundle with the help of this bundle : https://github.com/a2lix/TranslationFormBundle
Now, i want to have my translated field in the admin list.
At this time, it's work with this method:
/**
* @ORMEntity
* @ORMTable(name="sport")
*/
class Sport
{
...
public function getNom(){
return $this->translate()->getNom();
}
}
It's work but, i have to remap all the translated field in the original entity. I'm pretty sure i'm missing something, particularly with the magic of the proxy translations.
UPDATE:
class Sport
{
use KnpDoctrineBehaviorsModelTranslatableTranslatable;
public function __call($method, $arguments)
{
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
/**
* @ORMColumn(type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
private $id;
// Need this method for the admin list template
public function getNom(){
return $this->translate()->getNom();
}
// Work even the precedent method not here, the proxy call work fine.
public function __toString(){
return $this->getNom();
}
}
class SportTranslation
{
use ORMBehaviorsTranslatableTranslation;
/**
* @ORMColumn(type="string", length=255)
*/
protected $nom;
/**
* @return string
*/
public function getNom()
{
return $this->nom;
}
/**
* @param string
* @return null
*/
public function setNom($nom)
{
$this->nom = $nom;
}
}
Thanks for your fast reply @nifr! The proxy Method work in a controller (i try on the __toString Method of sport, it's work fine).
But the issue apparently coming from sonata admin bundle, i check the template code, don't know why it doesn't work.
I will keep the ugly method until i finda better solution.
At this time it's the only way to print value in the admin list template.
If i find something better i will update this post.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…