[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.
@i-just is already working on this.
Since Nov 29, 2024.
- 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:
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
- Set maxSlugIncrement => 1
- Create an enabled entry called "My Test" in the CP
- Entry saves ok and is enabled with the slug
my-test - Create another enabled entry called "My Test" in the CP
Expected behavior
- Entry save fails and throws the uri error:
Could not generate a unique URI based on the URI formator similar (eg slug / uri already taken)
Actual behavior
- Entry saves ok with the non unique slug
my-testand 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.