Skip to content

Commit e933d64

Browse files
authored
Merge pull request #18722 from craftcms/feature/add-as-new-draft
Duplicate drafts from element editor
2 parents 349d223 + e3ca4dc commit e933d64

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

CHANGELOG-WIP.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Text condition rules now have “does not equal” operators.
1414
- Editable table columns now set `min-width` styles based on their configured widths, if set. ([#18534](https://github.com/craftcms/cms/issues/18534))
1515
- Entry post dates are no longer automatically set until the entry is fully saved as enabled. ([#18642](https://github.com/craftcms/cms/pull/18642))
16+
- Element edit screens now have a “Save as a new draft” action when editing an explicitly-created draft. ([#18722](https://github.com/craftcms/cms/pull/18722))
1617
- Address edit screens now have “Field settings” action menu items. ([#18544](https://github.com/craftcms/cms/discussions/18544))
1718
- Asset edit screens now have “Volume settings” and “Filesystem settings” action menu items. ([#18544](https://github.com/craftcms/cms/discussions/18544))
1819
- Entries’ “Entry type settings” and “Section settings” action menu items are now only shown for element edit screens’ primary action menus.

src/base/Element.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4006,6 +4006,15 @@ public function getAltActions(): array
40064006
}
40074007
}
40084008

4009+
if ($this->getIsDraft() && !$this->getIsUnpublishedDraft() && !$this->isProvisionalDraft) {
4010+
$altActions[] = [
4011+
'label' => Craft::t('app', 'Save as a new {type}', [
4012+
'type' => Craft::t('app', 'draft'),
4013+
]),
4014+
'action' => 'elements/duplicate',
4015+
];
4016+
}
4017+
40094018
// Fire a 'defineAltActions' event
40104019
if ($this->hasEventHandlers(self::EVENT_DEFINE_ALT_ACTIONS)) {
40114020
$event = new DefineAltActionsEvent([

src/controllers/ElementsController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,9 +1659,11 @@ public function actionDuplicate(): ?Response
16591659
$elementsService = Craft::$app->getElements();
16601660
$user = static::currentUser();
16611661

1662+
$isExplicitDraft = $element->getIsDraft() && !$element->getIsUnpublishedDraft() && !$element->isProvisionalDraft;
1663+
16621664
// save as a new is now available to people who can create drafts
16631665
$asUnpublishedDraft = $this->_asUnpublishedDraft && $element::hasDrafts();
1664-
if ($asUnpublishedDraft) {
1666+
if ($asUnpublishedDraft || $isExplicitDraft) {
16651667
$authorized = $elementsService->canDuplicateAsDraft($element, $user);
16661668
} else {
16671669
$authorized = $elementsService->canDuplicate($element, $user);
@@ -1673,7 +1675,7 @@ public function actionDuplicate(): ?Response
16731675

16741676
$newAttributes = [
16751677
'isProvisionalDraft' => false,
1676-
'draftId' => null,
1678+
'draftId' => $isExplicitDraft ? $element->draftId : null,
16771679
];
16781680

16791681
if ($asUnpublishedDraft &&

0 commit comments

Comments
 (0)