Bliss
Bliss

Reputation: 25

How to combine Sluggable and Translatable

Well, I know that this question was asked so many times, but I promise that I read them all...

I use the StofDoctrineExtensions bundle. Its config seems okay because when I add my category with the locale default (fr), it works.

But, when I want to add a translation in english (en), the line related to the slug in the table ext_translations keeps displaying NULL... Don't know why.

My entity:

/**
 * @Gedmo\Slug(fields={"name"})
 * @ORM\Column(length=255, unique=true)
 * @Gedmo\Translatable
 */
private $slug;

/**
 * @var string
 *
 * @Gedmo\Translatable
 * @ORM\Column(name="name", type="string", length=255)
 */
private $name;

My Controller:

$category->setDateUpd(time());
$category->setTranslatableLocale($locale);
$category->getImage1()->setTranslatableLocale($locale);
$category->getImage2()->setTranslatableLocale($locale);
$em->persist($category);
$em->flush();

Samples of the ext_translations table:

id: 31 
locale: en
object_class: Bliss\ArticleBundle\Entity\Category
field: name
foreign_key: 14
content: South India

id: 33 
locale: en
object_class: Bliss\ArticleBundle\Entity\Category
field: slug
foreign_key: 14
content: NULL

Let me know if you need further information.

Upvotes: 0

Views: 86

Answers (1)

Bliss
Bliss

Reputation: 25

I suppose that I needed to post on StackOverflow to find an answer after 2 days... Well, I'm very happy anyway!

I updated the listener: DoctrineExtensionListener, and added the sluggable line before the translatable one:

public function onLateKernelRequest(GetResponseEvent $event)
{
    $sluggable =  $this->container->get('gedmo.listener.sluggable');

    $translatable = $this->container->get('gedmo.listener.translatable');
    $translatable->setTranslatableLocale($event->getRequest()->getLocale());
}

Thanks for your time, Bliss

Upvotes: 1

Related Questions