0

I use Symfony 3 framework and the sluggable doctrine extension. I need generate a slug with code like this:

<?php
/**
 * @Gedmo\Mapping\Annotation\Slug(handlers={
 *      @Gedmo\Mapping\Annotation\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={
 *          @Gedmo\Mapping\Annotation\SlugHandlerOption(name="parentRelationField", value="parent"),
 *          @Gedmo\Mapping\Annotation\SlugHandlerOption(name="separator", value="/")
 *      })
 * }, fields={"title", "code"})
 * @Doctrine\ORM\Mapping\Column(length=64, unique=true)
 */
private $slug;

I use TreeSlugHandler, but I want to use this handler, only if a slug is not set (if it's empty), because the handler rewrite the slug. How could I achieve that?

1 Answers1

0

You need to set updatable to false. The documentation is here

The relevant line is :

updatable (optional, default=true) - true to update the slug on sluggable field changes, false - otherwise

Ex:

/**
 * @Gedmo\Slug(fields={"meta_title"}, updatable=false)
 * @ORM\Column(length=128, unique=true)
 */
private $slug = "";
Adrien LAMOTTE
  • 548
  • 4
  • 8