Skip to content

Commit

Permalink
Revert "Merge pull request #16252 from craftcms/bugfix/16243-show-val…
Browse files Browse the repository at this point in the history
…idation-error-when-uri-not-unique"

This reverts commit 7debe97, reversing
changes made to f5ff672.
  • Loading branch information
brandonkelly committed Dec 9, 2024
1 parent 46853f1 commit 2cab5c8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 0 additions & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/services/Drafts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
6 changes: 6 additions & 0 deletions src/services/Elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down

0 comments on commit 2cab5c8

Please sign in to comment.