I have three entities, let's say A
, B
and C
. A
owns two ManyToOne relationships to B
and to C
. I want to generate a slug for A
, composed of field A.a
, B.b
and C.c
.
For the moment, I could generate a slug with A.a
and B.b
, with this code:
Class A:
<?php
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(
* repositoryClass="AppBundle\Repository\ARepository"
* )
*/
class A
{
/**
* @var integer
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private $id;
/**
* @var string
* @ORM\Column(type="string")
*/
private $name;
/**
* @var B
* @ORM\ManyToOne(targetEntity="B")
*/
private $b;
/**
* @var C
* @ORM\ManyToOne(targetEntity="C")
*/
private $c;
/**
* @var string
* @ORM\Column(type="string", unique=true)
* @Gedmo\Slug(handlers={
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\RelativeSlugHandler", options={
* @Gedmo\SlugHandlerOption(name="relationField", value="name"),
* @Gedmo\SlugHandlerOption(name="relationSlugField", value="alias"),
* @Gedmo\SlugHandlerOption(name="separator", value="-")
* })
* }, separator="-", updatable=true, fields={"name"})
*/
private $slug;
// ...
}
Class B :
<?php
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(
* repositoryClass="AppBundle\Repository\BRepository"
* )
*/
class B
{
/**
* @var integer
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
private $id;
/**
* @var string
* @ORM\Column(type="string")
*/
private $name;
/**
* @var string
* @ORM\Column(type="string")
* @Gedmo\Slug(handlers={
* @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\InversedRelativeSlugHandler", options={
* @Gedmo\SlugHandlerOption(name="relationClass", value="AppBundle\Entity\A"),
* @Gedmo\SlugHandlerOption(name="mappedBy", value="b"),
* @Gedmo\SlugHandlerOption(name="inverseSlugField", value="slug")
* })
* }, fields={"name"})
*/
private $alias;
//...
}
With this code, the slug A.slug
is something like {{B.alias}}-{{A.name}}
. I want it to be {{C.alias}}-{{B.alias}}-{{A.name}}
. I tried adding another SlugHander
in the handlers
array option of Gedmo\Slug
, but it ignored the second one. How can I accomplish that?