craftcms / craftcms/cms

[4.x]: Disabling slug increment in the config does not prevent saving of and element with a non-unique slug / uri when saved in the CP, disabling instead.

Open
#16,243 0 comments 0 reactions 1 assignee View on GitHub

@i-just is already working on this.

Since Nov 29, 2024.

bug craft4
Dominant language
PHP
Stars
3.6k
Forks
705
Avg merge
1d 5h
Merged PRs (30d)
134

Description

What happened?
Description

Setting the maxSlugIncrement slug to 1 is the suggested way to disable automatic slug increment feature(eg -1 -2 up to the maximum value). Currently trying to save an element, with a non unique slug / uri, in the CP does not prevent save, instead it disables and appears to save successfully. Having discussed with Tommy from the support team, we agreed that we expected it to throw an error and prevent the save.

Saving programatically does not have this issue, with the caveat that the uri is only validated if the element is enabled, see:

https://github.com/craftcms/cms/blob/4ac4d02a8582d7d548b4ff4120aa0bab9dbe3e49/src/validators/ElementUriValidator.php#L58-L65

I would have expected this to be handled by / respect the scenarios set on the validation rule, currently default, essential and live:

$rules[] = [['uri'], ElementUriValidator::class, 'on' => [self::SCENARIO_DEFAULT, self::SCENARIO_LIVE, self::SCENARIO_ESSENTIALS]];
Steps to reproduce
  1. Set maxSlugIncrement => 1
  2. Create an enabled entry called "My Test" in the CP
  3. Entry saves ok and is enabled with the slug my-test
  4. Create another enabled entry called "My Test" in the CP
Expected behavior
  1. Entry save fails and throws the uri error: Could not generate a unique URI based on the URI format or similar (eg slug / uri already taken)
Actual behavior
  1. Entry saves ok with the non unique slug my-test and is disabled

NB. Not checked if this also impacts [5.x]

Craft CMS version

4.12.5

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.