Search code examples
symfonyslug

Is it possible to specify forbidden values on a slug field?


I have an entity which have a slug field defined and managed using Gedmo Slug library.

Is it possible to easily define a list of unwanted values for this field (e.G. 'edit', 'new', 'delete'...) or do I need to make something all by myself?


Solution

  • You could use a SlugHandler I guess.

    Take a look at this : http://atlantic18.github.io/DoctrineExtensions/doc/sluggable.html#slug-handlers

    You could create your own SlugHandler, add some SlugHandlerOption with your forbidden words, and use a simple regex to check if the generated slug is valid.

    If not, you could modify the generated slug or throw an exception.