diff --git a/CHANGELOG-WIP.md b/CHANGELOG-WIP.md index c0ed85ff82a..56163672d01 100644 --- a/CHANGELOG-WIP.md +++ b/CHANGELOG-WIP.md @@ -2,7 +2,6 @@ ## Content Management - The global sidebar no longer shows “Failed” for queue jobs, for users that don’t have access to the Queue Manager. ([#16184](https://github.com/craftcms/cms/issues/16184)) -- Elements with non-unique URIs now show a validation error rather than become disabled. ([#16243](https://github.com/craftcms/cms/issues/16243), [#16252](https://github.com/craftcms/cms/pull/16252)) ## Administration - The Queue Manager utility now shows jobs’ class names. ([#16228](https://github.com/craftcms/cms/pull/16228)) diff --git a/src/controllers/ElementsController.php b/src/controllers/ElementsController.php index 018f50b53d3..b219d41284c 100644 --- a/src/controllers/ElementsController.php +++ b/src/controllers/ElementsController.php @@ -1220,7 +1220,7 @@ public function actionDuplicate(): ?Response 'isProvisionalDraft' => false, ]); } catch (InvalidElementException $e) { - return $this->_asFailure($element, Craft::t('app', 'Couldn’t duplicate {type}.', [ + return $this->_asFailure($e->element, Craft::t('app', 'Couldn’t duplicate {type}.', [ 'type' => $element::lowerDisplayName(), ])); } catch (Throwable $e) { diff --git a/src/services/Drafts.php b/src/services/Drafts.php index 9f246c1bad0..33e3b446b26 100644 --- a/src/services/Drafts.php +++ b/src/services/Drafts.php @@ -372,6 +372,12 @@ public function removeDraftData(ElementInterface $draft): void $draft->setScenario(Element::SCENARIO_ESSENTIALS); $draft->validate(); + // If there are any errors on the URI, re-validate as disabled + if ($draft->hasErrors('uri') && $draft->enabled) { + $draft->enabled = false; + $draft->validate(); + } + try { if ($draft->hasErrors() || !Craft::$app->getElements()->saveElement($draft, false)) { throw new InvalidElementException($draft, "Draft $draft->id could not be applied because it doesn't validate."); diff --git a/src/services/Elements.php b/src/services/Elements.php index 453944dc314..b89923fed02 100644 --- a/src/services/Elements.php +++ b/src/services/Elements.php @@ -1636,6 +1636,12 @@ public function duplicateElement( $mainClone->setScenario(Element::SCENARIO_ESSENTIALS); $mainClone->validate(); + // If there are any errors on the URI, re-validate as disabled + if ($mainClone->hasErrors('uri') && $mainClone->enabled) { + $mainClone->enabled = false; + $mainClone->validate(); + } + if ($mainClone->hasErrors()) { throw new InvalidElementException($mainClone, 'Element ' . $element->id . ' could not be duplicated because it doesn\'t validate.'); }