diff --git a/resources/js/components/entries/PublishActions.vue b/resources/js/components/entries/PublishActions.vue index 77c9d8b589..77476c702d 100644 --- a/resources/js/components/entries/PublishActions.vue +++ b/resources/js/components/entries/PublishActions.vue @@ -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')); } diff --git a/src/Entries/Collection.php b/src/Entries/Collection.php index 28193e31f2..c24b83f7c5 100644 --- a/src/Entries/Collection.php +++ b/src/Entries/Collection.php @@ -59,6 +59,7 @@ class Collection implements Arrayable, ArrayAccess, AugmentableContract, Contrac protected $titleFormats = []; protected $previewTargets = []; protected $autosave; + protected $draftWithoutValidation = false; public function __construct() { @@ -851,4 +852,9 @@ public function augmentedArrayData() 'handle' => $this->handle(), ]; } + + public function draftWithoutValidation($draftWithoutValidation = null) + { + return $this->fluentlyGetOrSet('draftWithoutValidation')->args(func_get_args()); + } } diff --git a/src/Http/Controllers/CP/Collections/EntriesController.php b/src/Http/Controllers/CP/Collections/EntriesController.php index 1a2057f65d..98efbc5462 100644 --- a/src/Http/Controllers/CP/Collections/EntriesController.php +++ b/src/Http/Controllers/CP/Collections/EntriesController.php @@ -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(); @@ -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']); diff --git a/src/Http/Controllers/CP/Collections/PublishedEntriesController.php b/src/Http/Controllers/CP/Collections/PublishedEntriesController.php index 823ecc1100..ef41823a50 100644 --- a/src/Http/Controllers/CP/Collections/PublishedEntriesController.php +++ b/src/Http/Controllers/CP/Collections/PublishedEntriesController.php @@ -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; @@ -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()), diff --git a/src/Stache/Stores/CollectionsStore.php b/src/Stache/Stores/CollectionsStore.php index b81d6a086b..cecf258ac4 100644 --- a/src/Stache/Stores/CollectionsStore.php +++ b/src/Stache/Stores/CollectionsStore.php @@ -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