softDoctrineExtension : Tree (MaterializedPath) + sluggable + Translatable = Fail :/
Bonjour tout le monde,
j'utilise le softdoctrineExtensionBundle sur une entity Place. (cf classe jointe)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinColumn as JoinColumn;
use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @Gedmo\Tree(type="materializedPath")
* @Gedmo\TranslationEntity(class="PlaceTranslation")
* @ORM\Table(name="`place`")
* @ORM\Entity(repositoryClass="PlaceRepository")
*/
class Place {
/**
* @ORM\Id
* @ORM\Column(name="geoname_id", type="integer")
*/
protected $geonameId;
/**
* @Gedmo\TreeParent
* @ORM\ManyToOne(targetEntity="Place", inversedBy="children")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="geoname_id_parent", referencedColumnName="geoname_id", onDelete="CASCADE")
* })
*/
protected $parent;
/**
* @ORM\OneToMany(targetEntity="Place", mappedBy="parent")
* @var ArrayCollection
*/
protected $children;
/**
* @Gedmo\TreeLevel
* @ORM\Column(type="integer", nullable=true)
*/
protected $level;
/**
* @Gedmo\Translatable
* @ORM\Column(type="string", length=200)
*/
protected $name;
/**
* @Gedmo\Translatable
* @Gedmo\Slug(fields={"name"})
* @Gedmo\TreePathSource
* @ORM\Column(length=200, unique=true)
*/
protected $slug;
/**
* @Gedmo\Translatable
* @Gedmo\TreePath(separator="/", appendId=false, endsWithSeparator=false)
* @ORM\Column(name="path", type="string", length=3000, nullable=true)
*/
protected $path;
/**
* Constructor
*/
public function __construct()
{
$this->children = new ArrayCollection();
}
} |
Notamment l'extension Tree en materialized_path(gestion des "place" parents/enfants), Slug (à partir du "name") & Translatable conjointement.
Ma conf (app/config.yml)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
orm:
auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
default:
auto_mapping: true
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable # (optional) it will default to the name set for the mapping
is_bundle: false
gedmo_translator:
type: annotation
prefix: Gedmo\Translator\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
alias: GedmoTranslator # (optional) it will default to the name set for the mapping
is_bundle: false
gedmo_loggable:
type: annotation
prefix: Gedmo\Loggable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Loggable/Entity"
alias: GedmoLoggable # (optional) it will default to the name set for the mappingmapping
is_bundle: false
gedmo_tree:
type: annotation
prefix: Gedmo\Tree\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
alias: GedmoTree # (optional) it will default to the name set for the mapping
is_bundle: false
# Stof Doctrine Extensions Configuration
stof_doctrine_extensions:
default_locale: "%locale%"
translation_fallback: true
orm:
default:
translatable: true
sluggable: true
tree: true |
Mes annotations me generent 2 tables correctement : "place" & "place_translations"
Ma locale par défaut est "en_US".
Dans mon controlleur, lorsque je fait le traitement suivant :
Code:
1 2 3 4 5 6
|
$place = $placeRepository->findOneByGeonameId(1024032);
$place->setName('mon nom en francais');
$place->setTranslatableLocale('fr_FR');
$em->persist($place);
$em->flush(); |
Mon "name" et "slug" sont bien générés et traduit dans la table place_translation.
En revanche mon path (materialized path) se met à jour et est traduit dans ma table place d'origine et non dans ma table place_translation.
Je pense que cela vient de l'ordre des listeners du softdoctrine et j'ai de ce fait essayé les différentes solutions proposées sur le web, mais aucun résultat probant.
Solutions testées :
solution 1 : dans mon __construct de mon entity place :
Code:
1 2 3 4 5 6 7 8 9
|
$evm = new \Doctrine\Common\EventManager();
$sluggableListener = new \Gedmo\Sluggable\SluggableListener();
$evm->addEventSubscriber($sluggableListener);
$treeListener = new \Gedmo\Tree\TreeListener();
$evm->addEventSubscriber($treeListener);
$translatableListener = new \Gedmo\Translatable\TranslatableListener();
$translatableListener->setTranslatableLocale($this->getTranslatableLocale());
$evm->addEventSubscriber($translatableListener); |
solution 2 : jouer avec les setHint()
4 jours que je suis dessus et ce doit etre un truc tout con, mais je bloque.
Des idées ?