Skip to content

Commit

Permalink
No more draft auto-creation
Browse files Browse the repository at this point in the history
Resolves #4549
Resolves #4535
  • Loading branch information
brandonkelly committed Jul 15, 2019
1 parent f3b9fa0 commit a658ad4
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 225 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
### Added
- Added `craft\web\UrlManager::setMatchedElement()`.

### Changed
- Craft no longer creates drafts automatically when editing entries. The user must click a “Save as a Draft” button to create one. ([#4549](https://github.com/craftcms/cms/issues/4549))
- Entries are now immediately savable, whether or not any changes were made. ([#4535](https://github.com/craftcms/cms/issues/4535))
- It’s no longer possible to preview entries’ Current revision. A draft must be created first.

### Fixed
- Fixed a bug where it wasn’t possible to delete Matrix blocks if Min Blocks and Max Blocks were set to the same value, and an element already had more than that many blocks. ([#4562](https://github.com/craftcms/cms/issues/4562))
- Fixed a bug where `craft\web\UrlManager::getMatchedElement()` could return the incorrect result on preview requests. ([#4542](https://github.com/craftcms/cms/issues/4542))
Expand Down
1 change: 0 additions & 1 deletion src/controllers/EntryRevisionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ public function actionSaveDraft()
'draftNotes' => $draft->draftNotes,
'docTitle' => $this->docTitle($draft),
'title' => $this->pageTitle($draft),
'duplicatedElements' => $elementsService::$duplicatedElementIds,
]);
}

Expand Down
69 changes: 41 additions & 28 deletions src/templates/_layouts/element.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- canUpdateSource (optional): whether the current user is allowed to update the source element
(e.g. by publishing a draft or reverting the element to a prior revision).
- shareUrl (optional): the URL that the Share button should link to.
- saveSourceAction: the controller action that should be used to save the source element
- saveDraftAction: the controller action that should be used to save a draft
- deleteDraftAction: the controller action that should be used to delete a draft
- applyDraftAction: the controller action that should be used to apply a draft onto the source element
Expand All @@ -31,11 +32,12 @@
url: element.uri == '__home__' ? '' : element.uri
}]|merge(previewTargets) %}
{% endif %}
{% set enablePreview = previewTargets and not craft.app.request.isMobileBrowser(true) %}
{% set enablePreview = (isDraft or isRevision) and previewTargets and not craft.app.request.isMobileBrowser(true) %}

{% set canDeleteDraft = isDraft and not isUnsavedDraft and ((canDeleteDraft ?? false) or element.creatorId == currentUser.id) %}
{% set canUpdateSource = canUpdateSource ?? false %}
{% set shareUrl = shareUrl ?? null %}
{% set saveSourceAction = saveSourceAction ?? null %}
{% set revertSourceAction = revertSourceAction ?? null %}

{% if not isRevision %}
Expand All @@ -60,49 +62,60 @@
{{ block('pageTitle') }}
{{ block('contextMenu') }}
<div class="flex-grow"></div>

{% if previewTargets %}
<div class="spacer"></div>
<div class="btngroup">
{% if enablePreview %}
<div id="preview-btn" class="btn">{{ "Preview"|t('app') }}</div>
{% endif %}
<div id="share-btn" class="btn">{{ 'Share'|t('app') }}</div>
</div>
{% endif %}
{{ block('actionButton') }}
{% endblock %}

{% block contextMenu %}
{% include "_includes/revisionmenu" %}
{% endblock %}

{% block actionButton %}
{% if canUpdateSource or isUnsavedDraft %}
{% if isRevision %}
{% if revertSourceAction %}
<div class="spacer"></div>
<form method="post" accept-charset="UTF-8">
{{ csrfInput() }}
<input type="hidden" name="action" value="{{ revertSourceAction }}">
{{ redirectInput(element.cpEditUrl) }}
<input type="hidden" name="revisionId" value="{{ element.revisionId }}">
<div class="secondary-buttons">
<input type="button" class="btn submit formsubmit" value="{{ 'Revert {type} to this revision'|t('app', { type: element.displayName()|lower }) }}">
</div>
</form>
{% endif %}
{% else %}
<div class="spacer"></div>
{% if isUnsavedDraft %}
<input type="submit" id="apply-btn" class="btn submit" value="{{ 'Save {type}'|t('app', { type: element.displayName() }) }}">
{% block actionButton %}
{% if canUpdateSource or isUnsavedDraft %}
{% if isRevision %}
{% if revertSourceAction %}
<div class="spacer"></div>
<form method="post" accept-charset="UTF-8">
{{ csrfInput() }}
<input type="hidden" name="action" value="{{ revertSourceAction }}">
{{ redirectInput(element.cpEditUrl) }}
<input type="hidden" name="revisionId" value="{{ element.revisionId }}">
<div class="secondary-buttons">
<input type="button" class="btn submit formsubmit" value="{{ 'Revert {type} to this revision'|t('app', { type: element.displayName()|lower }) }}">
</div>
</form>
{% endif %}
{% else %}
<input type="submit" id="apply-btn" class="btn submit{% if not isDraft %} disabled{% endif %}" value="{{ 'Update {type}'|t('app', { type: element.displayName() }) }}">
<div class="spacer"></div>
{% if isUnsavedDraft %}
<input type="submit" id="apply-btn" class="btn submit" value="{{ 'Save {type}'|t('app', { type: element.displayName() }) }}">
{% elseif isDraft %}
<input type="submit" id="apply-btn" class="btn submit{% if not isDraft %} disabled{% endif %}" value="{{ 'Update {type}'|t('app', { type: element.displayName() }) }}">
{% else %}
{% if saveSourceAction %}
<input type="submit" id="apply-btn" class="btn submit" value="{{ 'Save {type}'|t('app', { type: element.displayName() }) }}">
<div class="spacer"></div>
{% endif %}
{% set draftRedirectUrl = url(element.cpEditUrl, {draftId: '__DRAFT_ID__'})|replace('__DRAFT_ID__', '{draftId}') %}
<input type="button" id="save-draft-btn" class="btn secondary formsubmit" value="{{ 'Save as a Draft'|t('app') }}" data-action="{{ saveDraftAction }}" data-redirect="{{ draftRedirectUrl|hash }}">
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endblock %}
{% endblock %}

{% block contextMenu %}
{% include "_includes/revisionmenu" %}
{% endblock %}

{% block main %}
{{ redirectInput(element.cpEditUrl) }}
{% if not isDraft and not isRevision and saveSourceAction %}
<input type="hidden" name="action" value="{{ saveSourceAction }}">
{% endif %}
{% if fullPageForm and craft.app.isMultiSite %}
<input type="hidden" name="siteId" value="{{ element.siteId }}">
{% endif %}
Expand Down
3 changes: 2 additions & 1 deletion src/templates/entries/_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
{% set isRevision = entry.getIsRevision() %}

{% set element = entry %}
{% set saveSourceAction = 'entries/save-entry' %}
{% set saveDraftAction = 'entry-revisions/save-draft' %}
{% set deleteDraftAction = 'entry-revisions/delete-draft' %}
{% set applyDraftAction = 'entry-revisions/publish-draft' %}
Expand All @@ -25,7 +26,7 @@
{% if not isSingle and not isRevision and (canUpdateSource or canDeleteEntry) and not entry.isUnsavedDraft %}
<div class="spacer"></div>
<div>
<div id="action-menubtn" class="btn menubtn" data-icon="settings" title="{{ 'Actions'|t('app') }}"></div>
<div id="action-menubtn" class="btn secondary menubtn" data-icon="settings" title="{{ 'Actions'|t('app') }}"></div>
<div class="menu">
<ul>
{% if canUpdateSource %}
Expand Down
25 changes: 18 additions & 7 deletions src/web/assets/cp/dist/css/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,8 @@ ul.icons li a:hover {
background-image: url(../images/spinner_submit.gif);
}

.secondary-buttons .btn.icon.add.loading.submit:after {
.secondary-buttons .btn.icon.add.loading.submit:after,
.btn.secondary.icon.add.loading.submit:after {
background-image: url(../images/spinner_submit_secondary.gif);
}

Expand Down Expand Up @@ -1215,12 +1216,16 @@ ul.icons li a:hover {
}

/* submit buttons */
.btn.submit {
.btn.submit,
.btn.secondary {
color: #fff;
background-image: linear-gradient($submitColor, #cc5643);
@include light-on-dark-text;
}

.btn.submit {
background-image: linear-gradient($submitColor, #cc5643);
}

.btn.submit:not(.disabled):not(.inactive):hover,
.btn.submit:not(.disabled):not(.inactive).hover {
background-image: linear-gradient($submitHoverColor, #b34b3b);
Expand All @@ -1231,17 +1236,22 @@ ul.icons li a:hover {
background-image: linear-gradient($submitActiveColor, #994032);
}

.secondary-buttons .btn.submit {
.secondary-buttons .btn.submit,
.btn.secondary {
background-image: linear-gradient($secondarySubmitColor, #878f99);
}

.secondary-buttons .btn.submit:not(.disabled):not(.inactive):hover,
.secondary-buttons .btn.submit:not(.disabled):not(.inactive).hover {
.secondary-buttons .btn.submit:not(.disabled):not(.inactive).hover,
.btn.secondary:not(.disabled):not(.inactive):hover,
.btn.secondary:not(.disabled):not(.inactive).hover {
background-image: linear-gradient($secondarySubmitHoverColor, #697480);
}

.secondary-buttons .btn.submit:not(.disabled):not(.inactive):active,
.secondary-buttons .btn.submit:not(.disabled):not(.inactive).active {
.secondary-buttons .btn.submit:not(.disabled):not(.inactive).active,
.btn.secondary:not(.disabled):not(.inactive):active,
.btn.secondary:not(.disabled):not(.inactive).active {
background-image: linear-gradient($secondarySubmitActiveColor, #697380);
}

Expand Down Expand Up @@ -4760,7 +4770,8 @@ only screen and (min-resolution: 1.5dppx) {
.btn.icon.add.loading.submit:after {
background-image: url(../images/spinner_submit_2x.gif);
}
.secondary-buttons .btn.icon.add.loading.submit:after {
.secondary-buttons .btn.icon.add.loading.submit:after,
.btn.secondary.icon.add.loading.submit:after {
background-image: url(../images/spinner_submit_secondary_2x.gif);
}

Expand Down
14 changes: 8 additions & 6 deletions src/web/assets/cp/dist/css/craft.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/web/assets/cp/dist/css/craft.css.map

Large diffs are not rendered by default.

Loading

0 comments on commit a658ad4

Please sign in to comment.