Cms: [Feature Request] Option to require unique slugs

Created on 10 Aug 2018  Â·  7Comments  Â·  Source: craftcms/cms

Description

Ability to have a section who generates only unique slugs using incremental suffixes, even if this section has no URLs for entries

Steps to reproduce

  1. Create a new section (or modify existing one)
  2. Checkbox or switch "Make all slugs unique accross this section"
  3. If existing section, validate all entries of the section priorly to make them uniques if duplicates are already found. Perhaps it can also be a good idea to ask user what to do with duplicates (nothing or make them unique) or to inform him that some duplicates slugs will change before doing it.
enhancement

Most helpful comment

Craft has a maxSlugIncrement config option. If you set this to 1, Craft will not allow an entry to be saved with a duplicate slug.

All 7 comments

This is also true with other element types (category groups w/o URLs).

This caught me by surprise – I was under the impression slugs always had to be unique (within section/group, and on the the same structure depth), which really seems the way they are useful, and how most people think of them (AFAIK).

Currently Craft only cares that the resulting URIs are unique, and only for elements that have URIs. It will increment the slug only as a way to produce a unique URI; whether the slug itself is unique or not doesn’t matter.

Craft has a maxSlugIncrement config option. If you set this to 1, Craft will not allow an entry to be saved with a duplicate slug.

@jamiewade - There is a bug with maxSlugIncrement. If you save an entry with disabled status it still generates duplicated slug.

$entry = new Entry();
$entry->enabled = false;
$entry->title = "test";
$return = Craft::$app->elements->saveElement($entry);

@bruno-canada Please can you create a new issue to report this

For posterity, things are currently working as expected – see https://github.com/craftcms/cms/issues/6152#issuecomment-635375476.

Was this page helpful?
0 / 5 - 0 ratings