l3pp4rd/DoctrineExtensions — Issue #194: TreeSlugHandler + Translatable
Author: luscarpa
Created: 2011-11-22 09:16:24+00:00
State: open

I have a problem with TreeSlugHandler and Translatable. Here a small example:

$food = new \App\Entity\Category();
$food->setName('Food');
$food->setTranslatableLocale('it_IT');

$fruits = new \App\Entity\Category();
$fruits->setName('Fruits');
$fruits->setParent($food);
$fruits->setTranslatableLocale('it_IT');

$vegetables = new \App\Entity\Category();
$vegetables->setName('Vegetables');
$vegetables->setParent($food);
$vegetables->setTranslatableLocale('it_IT');

$carrots = new \App\Entity\Category();
$carrots->setName('Carrots');
$carrots->setParent($vegetables);
$carrots->setTranslatableLocale('it_IT');

$this->_em->persist($food);
$this->_em->persist($fruits);
$this->_em->persist($vegetables);
$this->_em->persist($carrots);
$this->_em->flush()

With these settings I have the following slug:

food
food/fruits
food/vegetables
food/vegetables/carrots

Now, if I change food entry into 'Food New' with this code:

$category = $this->_em->getRepository('\App\Entity\Category')->findOneByName('Food');
$category->setName('Food New');

$this->_em->persist($category);
$this->_em->flush();

I get the right result:

food-new
food-new/fruits
food-new/vegetables
food-new/vegetables/carrots

But if I want to change also the italian translation

$category = $this->_em->getRepository('\App\Entity\Category')->findOneByName('Food');
$category->setName('Cibo');
$category->setTranslatableLocale('it_it');

$this->_em->persist($category);
$this->_em->flush();

I get this result that is wrong

cibo
food/fruits
food/vegetables
food/vegetables/carrots

Moreover if I change the category that is on the second level:

$category = $this->_em->getRepository('\App\Entity\Category')->findOneByName('Vegetables');
$category->setName('Ortaggi');
$category->setTranslatableLocale('it_it');

$this->_em->persist($category);
$this->_em->flush();

I get this

cibo
food/fruits
food-new/ortaggi
food/vegetables/carrots

I'm doing something wrong or there is a bug?