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. #16485

Closed

Conversation

epiqueras
Copy link
Contributor

@epiqueras epiqueras commented Jul 9, 2019

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 self-assigned this Jul 9, 2019
@epiqueras epiqueras added the [Status] In Progress Tracking issues with work in progress label Jul 9, 2019
@epiqueras epiqueras added this to the Future milestone Jul 9, 2019
@epiqueras epiqueras added [Package] Editor /packages/editor [Feature] Templates API Related to API powering block template functionality in the Site Editor labels Jul 9, 2019
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Is there an intermediate step where we refactor what exists today in editing the title and content to blocks, and leave the work with templates custom post type as a future iteration?

"title": {
"type": "string",
"source": "post",
"attribute": "title"
Copy link
Member

Choose a reason for hiding this comment

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

I might think to call this property, particularly if we just consider the post an object from which we're picking property values. Also avoids ambiguity on block attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went with attributes because all the selectors use "post attributes" as the terminology.

Copy link
Member

Choose a reason for hiding this comment

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

I went with attributes because all the selectors use "post attributes" as the terminology.

Hmm, that's fair. In retrospect I think they might have been more canonically referred to as properties of the post, but I'm fine targeting consistency if even for consistency's sake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I like "properties" more too.

@epiqueras
Copy link
Contributor Author

Is there an intermediate step where we refactor what exists today in editing the title and content to blocks, and leave the work with templates custom post type as a future iteration?

I could remove the persistence to the template CPT post, but don't you think it's pretty trivial?

@youknowriad
Copy link
Contributor

@epiqueras I don't really think persistence is trivial. There's a lot of unanswered questions:

  • How do themes define these templates
  • Can we assign a persisted and a theme template (file)?
  • How do they relate to the template hierarchy, and how to show them in frontend?
  • What does it mean to save a "draft"? Do we update the template and save the post as a draft or both as a draft? What about scheduling?

@aduth aduth force-pushed the try/custom-sources-2 branch from d955e89 to 468f908 Compare July 10, 2019 18:15
@epiqueras
Copy link
Contributor Author

@youknowriad Right, these are all the right questions. What I meant is that it's trivial in the way that it's implemented in this PR and all those questions can be solved/answered by building on top of this. Currently, the fact that it is even persisted, is just an implementation detail. We still only care about what is saved to post.post_content and post.title in the front end.

I think we should also discuss the vision for how we'll answer those questions. This is what I have in mind:

How do themes define these templates

Using a registerBlockTemplate PHP API.

Can we assign a persisted and a theme template (file)?

Yes, but the persisted one should take precedence like in #4659.

How do they relate to the template hierarchy, and how to show them in frontend?

We should take the approach taken in #4659 and also allow for template files to explicitly render persisted templates through a simple function call in the file.

What does it mean to save a "draft"? Do we update the template and save the post as a draft or both as a draft? What about scheduling?

Both as a draft, same for scheduling. I think this makes the most sense as you are editing everything at the same time.

To support a different approach we would have to redesign the interface to clearly differentiate between when you are selecting/editing a template block and a post content block and provide two different save buttons. Doing this in a user friendly and not clunky way will be hard.

@epiqueras epiqueras force-pushed the try/expanding-the-editor-outside-post-content branch from eaa31b9 to 22f9ce5 Compare July 10, 2019 20:29
@epiqueras epiqueras changed the base branch from try/custom-sources-2 to master July 10, 2019 20:30
@epiqueras
Copy link
Contributor Author

Ran

$ git rebase --onto master ac70c2f3c6f61a458f03f0739f95048da5ad7ea9 try/expanding-the-editor-outside-post-content

and changed the base of this PR to master because #16402 was merged.

@aduth
Copy link
Member

aduth commented Jul 11, 2019

Can you clarify: For custom post types which register their own template, does this pull request change so that suddenly they'll start storing a new wp_template custom post type when saving the post?

@epiqueras
Copy link
Contributor Author

Can you clarify: For custom post types which register their own template, does this pull request change so that suddenly they'll start storing a new wp_template custom post type when saving the post?

That would be one of the next steps.

@epiqueras
Copy link
Contributor Author

There was actually an incompatibility with the current template format, but it's fixed here now:

5afab34 Editor: Keep compatibility with current template format.

@epiqueras
Copy link
Contributor Author

I think I found a better approach for this. Closing for now.

@epiqueras epiqueras closed this Jul 12, 2019
@epiqueras
Copy link
Contributor Author

Reopened in #16565

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expanding the Editor outside of post_content
3 participants