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

Expose Gutenberg Data Format version in the REST API #6436

Merged
merged 5 commits into from
Apr 27, 2018

Conversation

pento
Copy link
Member

@pento pento commented Apr 26, 2018

Description

As described in #6435, it would be valuable to third party tools if we exposed a canonical block format version for the content of the current post, so they could decide how to handle the post.

For now, this is simply 0, for "no blocks", or 1, for "yes, there are 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.

@pento pento added the Core REST API Task Task for Core REST API efforts label Apr 26, 2018
@pento pento added this to the 2.8 milestone Apr 26, 2018
@pento pento self-assigned this Apr 26, 2018
@pento pento requested a review from a team April 26, 2018 07:22
lib/compat.php Outdated
array(
'get_callback' => 'gutenberg_get_content_block_format',
'schema' => array(
'description' => __( 'The current version of the block format that this post users.', 'gutenberg' ),
Copy link
Member

Choose a reason for hiding this comment

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

Typo: uses

@gziolo
Copy link
Member

gziolo commented Apr 26, 2018

551 | ERROR | [x] File must end with a newline character
| | (Generic.Files.EndFileNewline.NotFound)

From our friend phpcs.

@pento
Copy link
Member Author

pento commented Apr 26, 2018

🕺🏻

@danielbachhuber
Copy link
Member

I don't love this solution to the problem, as it seems to fall into the category of "let's shove a bunch of extra data onto the Post resource."

Can you describe the other approaches proposed?

We have a protected subattribute of content. Is block_version better suited on content, given Gutenberg works directly with the post content?

image

@pento
Copy link
Member Author

pento commented Apr 27, 2018

@danielbachhuber: I agree, that's definitely a better place to put it. Is there a filter for the schema that would let me add that? If not, register_rest_field() with a copy/pasta of the full content property from WP_REST_Posts_Controller is a reasonable hack for now.

@pento pento force-pushed the add/6435-block-format-version branch from 801e31f to f002329 Compare April 27, 2018 02:46
@pento
Copy link
Member Author

pento commented Apr 27, 2018

Actually, I just went with adding it to the post response for now. We can do it properly in the merge.

Copy link
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

Works and looks alright to me. I might wait for a second opinion, up to you. :)

@danielbachhuber danielbachhuber self-requested a review April 27, 2018 16:26
Copy link
Member

@danielbachhuber danielbachhuber left a comment

Choose a reason for hiding this comment

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

I've added a @todo marker for registering on the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core REST API Task Task for Core REST API efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants