Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[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. #16243

Open
samhibberd opened this issue Nov 29, 2024 · 0 comments
Assignees

Comments

@samhibberd
Copy link

samhibberd commented Nov 29, 2024

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:

if (
$model->enabled &&
$model->getEnabledForSite() &&
!$model->getIsUnpublishedDraft()
) {
$this->addError($model, $attribute, Craft::t('app', 'Could not generate a unique URI based on the URI format.'));
return;
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants