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] Allow entries to be drafted without requiring validation #8919

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions resources/js/components/entries/PublishActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ export default {

handleAxiosError(e) {
this.saving = false;

if (e.response && e.response.status === 422) {
const { message, errors } = e.response.data;
this.$store.commit(`publish/${this.publishContainer}/setErrors`, errors);
this.$toast.error(message);
return;
}

this.$toast.error(e || __('Something went wrong'));
}

Expand Down
6 changes: 6 additions & 0 deletions src/Entries/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Collection implements Arrayable, ArrayAccess, AugmentableContract, Contrac
protected $titleFormats = [];
protected $previewTargets = [];
protected $autosave;
protected $draftWithoutValidation = false;

public function __construct()
{
Expand Down Expand Up @@ -851,4 +852,9 @@ public function augmentedArrayData()
'handle' => $this->handle(),
];
}

public function draftWithoutValidation($draftWithoutValidation = null)
{
return $this->fluentlyGetOrSet('draftWithoutValidation')->args(func_get_args());
}
}
34 changes: 19 additions & 15 deletions src/Http/Controllers/CP/Collections/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,16 @@ public function update(Request $request, $collection, $entry)
->fields()
->addValues($data);

$fields
->validator()
->withRules(Entry::updateRules($collection, $entry))
->withReplacements([
'id' => $entry->id(),
'collection' => $collection->handle(),
'site' => $entry->locale(),
])->validate();
if (($fields->get('published')->value() && ! $entry->revisionsEnabled()) || ! $collection->draftWithoutValidation()) {
$fields
->validator()
->withRules(Entry::updateRules($collection, $entry))
->withReplacements([
'id' => $entry->id(),
'collection' => $collection->handle(),
'site' => $entry->locale(),
])->validate();
}

$values = $fields->process()->values();

Expand Down Expand Up @@ -349,13 +351,15 @@ public function store(Request $request, $collection, $site)
->fields()
->addValues($data);

$fields
->validator()
->withRules(Entry::createRules($collection, $site))
->withReplacements([
'collection' => $collection->handle(),
'site' => $site->handle(),
])->validate();
if ($fields->get('published')->value() || ! $collection->draftWithoutValidation()) {
$fields
->validator()
->withRules(Entry::createRules($collection, $site))
->withReplacements([
'collection' => $collection->handle(),
'site' => $site->handle(),
])->validate();
}

$values = $fields->process()->values()->except(['slug', 'blueprint', 'published']);

Expand Down
18 changes: 18 additions & 0 deletions src/Http/Controllers/CP/Collections/PublishedEntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Statamic\Http\Controllers\CP\Collections;

use Illuminate\Http\Request;
use Statamic\Facades\Entry;
use Statamic\Facades\User;
use Statamic\Http\Controllers\CP\CpController;
use Statamic\Http\Resources\CP\Entries\Entry as EntryResource;
Expand All @@ -13,6 +14,23 @@ public function store(Request $request, $collection, $entry)
{
$this->authorize('publish', $entry);

if ($collection->draftWithoutValidation()) {
$fields = $entry
->blueprint()
->ensureField('published', ['type' => 'toggle'])
->fields()
->addValues($entry->data()->all());

$fields
->validator()
->withRules(Entry::updateRules($collection, $entry))
->withReplacements([
'id' => $entry->id(),
'collection' => $collection->handle(),
'site' => $entry->locale(),
])->validate();
}

$entry = $entry->publish([
'message' => $request->message,
'user' => User::fromUser($request->user()),
Expand Down
3 changes: 2 additions & 1 deletion src/Stache/Stores/CollectionsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function makeItemFromFile($path, $contents)
->taxonomies(array_get($data, 'taxonomies'))
->propagate(array_get($data, 'propagate'))
->previewTargets($this->normalizePreviewTargets(array_get($data, 'preview_targets', [])))
->autosaveInterval(array_get($data, 'autosave'));
->autosaveInterval(array_get($data, 'autosave'))
->draftWithoutValidation(array_get($data, 'draft_without_validation', false));

if ($dateBehavior = array_get($data, 'date_behavior')) {
$collection
Expand Down
Loading