Repository navigation
[6.x] Allow Live Preview while creating entries - #15648
Open
matsantosz wants to merge 1 commit into
Open
matsantosz wants to merge 1 commit into
matsantosz wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When you're creating an entry, the Live Preview button doesn't show up. You have to save first and only then can you preview, which is a bit awkward when you're writing a brand new page and just want to see how it looks. On our side this happens all the time with landing pages, and people end up saving throwaway drafts only to get to the preview.
The backend already supports this. The create form gets a
livePreviewUrlpointing atcollections.entries.preview.create, and that route builds an unsaved entry and returns a token (there's already a test for it inPreviewEntryTest). What was missing was the button itself, plus one bug further down the line: when the preview page loads,EntryRepository::substitute()callsBlink::forget($item->id()), and since a new entry has no id yet, the request fails with a TypeError.This PR:
isCreatingchecksubstitute()skip the id based substitution when the entry has no id. The entry is still substituted by its URI, which is how the preview request finds it anyway.I added a test that previews an entry that was never saved and checks that the page renders with its values. Without the fix it fails with the Blink TypeError.