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

Editor: Operate on template CPT posts and add a default template with post title and content blocks. #16565

Closed
wants to merge 70 commits into from

Conversation

epiqueras
Copy link
Contributor

cc @youknowriad

Closes #16281

Description

This PR builds on @aduth 's work on #16402 to add backwards compatible support for making the editor operate on and persist to template CPT posts instead of the actual edited post.

It adds a single, default, editable template to the "post" post type which contains a new post-title block, which persists to the edited post's title, followed by a new post-content block, which persists to the edited post's post_content. Note that this post-content block produces no markup on save so that the template only stores the location of post-content relative to the other blocks in the template. When the template is rendered by a theme, either explicitly or dynamically like in #4659, a render callback for the block could fill in the viewed post's content.

Future work will be needed to allow users or theme authors to create a template hierarchy and apply them to specific posts.

How has this been tested?

Posts were edited and saved and it was verified that the template updated correctly when making changes outside of the post-content block, as well as the title for the post-title block, and the content for the post-content block.

Screenshots

ezgif com-video-to-gif

Types of Changes

New Feature: Operate on template CPT posts and add a default template with post title and content blocks.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@epiqueras epiqueras added [Status] In Progress Tracking issues with work in progress [Feature] Templates API Related to API powering block template functionality in the Site Editor [Package] Editor /packages/editor [Package] Block library /packages/block-library labels Jul 12, 2019
@epiqueras epiqueras added this to the Future milestone Jul 12, 2019
@epiqueras epiqueras self-assigned this Jul 12, 2019
@epiqueras epiqueras force-pushed the try/expanding-the-editor-outside-post-content branch from 5b4aa69 to 39745cf Compare July 14, 2019 20:45
@epiqueras epiqueras force-pushed the try/expanding-the-editor-outside-post-content branch from 39745cf to 07392e0 Compare July 14, 2019 20:49
@epiqueras
Copy link
Contributor Author

I've rebased the zoom prototyping out of this PR and into #16578 .

STORE_KEY,
'getEditedPostContent'
);

const template = ( yield select( STORE_KEY, 'getEditorSettings' ) ).template;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so you're using the current template editor setting as the actual "FSE template". The template property is meant to be the post_content template while the actual FSE template is something that get stored separately. There's a question to be asked about "naming confusion" and also whether we may want to absorb one use-case in another in the future but I think for now we may want to consider them as two separate entities.

Basically what I had in mind is something like that:

  • a separate template prop in the EditorProvider for the FSE template
  • The same way we have currentPost and edits for the post in the reducer, I think we'd need currentTemplate and templateEdits maybe.
  • a boolean prop or something like that in the EditorProvider to switch between FSE mode (showing the template blocks) and current mode (showing a PostTitle input and the PostContent blocks as root level)
  • Both core/post-content and core/post-title blocks should be dynamic blocks that render the actual post title and post content in the frontend.
  • Basically post-content.php file shouldn't have to be touched to be loaded in an editor that has a template as well.

Does that make sense?

Copy link
Contributor Author

@epiqueras epiqueras Jul 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was what I was planning, except I wasn't sure if I should change the way the template was being injected and was going to leave that for last so we could discuss it further.

From my zoom prototyping:

I started by trying to support insertions, replacements, and removals, but I quickly realized that it would take a pretty widespread refactor due to a lot of assumptions we make in the logic for getting insertion indexes and other data. I don't think the need for this feature warrants those changes. This makes me think that we might have to try a different approach for #16485 where the editor just switches between editing the template and editing post content with a static post title component like it does now.

So for next steps here I see:

  • Give the template its own reducer and make all the necessary refactors. (Use the 'block_editor_settings' filter to send it to the client in its own, new key.)
  • Implement the "zoom" as a toggle between setting up the editor with the template or post.
  • Implement the render callbacks of the post title and post content blocks.

…nd add a toggle between template and post mode.
@ellatrix
Copy link
Member

Merged part of #16678 as 19adb5c. This does not include a small rewrite of templateLock, to reduce the amount of file changes on this branch.

@ellatrix
Copy link
Member

Read-only mode enabled on post content in edd9eeb.

@mcsf mcsf force-pushed the try/expanding-the-editor-outside-post-content branch from 02fb194 to 8cfb1e4 Compare July 22, 2019 10:22
@epiqueras
Copy link
Contributor Author

Closing this as it was just a prototype and most of the functionality has already been merged in more granular PRs. See:

https://github.com/WordPress/gutenberg/labels/%5BFeature%5D%20Full%20Site%20Editing

@epiqueras epiqueras closed this Nov 20, 2019
@youknowriad youknowriad deleted the try/expanding-the-editor-outside-post-content branch November 21, 2019 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Templates API Related to API powering block template functionality in the Site Editor [Package] Block library /packages/block-library [Package] Editor /packages/editor [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expanding the Editor outside of post_content
8 participants