-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add block types REST API. #21065
Add block types REST API. #21065
Conversation
CC @kadamwhite for visibility. |
Regarding the question at #2751 (comment):
I don't know that it's been audited for accuracy lately, but the original Block Registration RFC might be a good source of properties expected to be needed? @gziolo has been working on some of the specifics around |
Yes, we discussed it already. The work was divided into two parts on Trac and this one covers what we had before on the server before we started introducing
I don't know what are patterns used for other endpoints in core, but I'm curious why not use |
+1 to this pattern. |
Co-authored-by: Andrew Duthie <andrew@andrewduthie.com>
Co-authored-by: Andrew Duthie <andrew@andrewduthie.com>
Co-authored-by: Andrew Duthie <andrew@andrewduthie.com>
Co-authored-by: Andrew Duthie <andrew@andrewduthie.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gziolo Anything you think is needed here, functionally-speaking?
Would we plan to include unit tests here? Or later in the experimental lifecycle? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything you think is needed here, functionally-speaking?
I had some minor comments but nothing blocking. As far as I remember there was a follow-up on Track that adds the rest of block fields/properties.
Co-authored-by: Andrew Duthie <andrew@andrewduthie.com>
Co-authored-by: Andrew Duthie <andrew@andrewduthie.com>
Overall looks good, I'd really like to see tests on the prepare item with the different supported properties. |
@TimothyBJacobs Do you need these now before approval or before core merge? |
I'd prefer to have them now, without them it is hard for me to tell if they are actually outputting what is expected. |
@TimothyBJacobs Does this test cover prepare? https://github.com/WordPress/gutenberg/pull/21065/files#diff-c43bb246f80bf07e6c00d6fdb3427794R129-R149 |
That covers when invalid data is provided, but not the positive case. |
Tests added for positive case. @TimothyBJacobs |
'additionalProperties' => array( | ||
'type' => 'object', | ||
), | ||
'default' => array(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I notice that, despite the fact the type
is assigned as 'object'
, when the default value is returned by the endpoint, it is returned as a JSON array []
instead of {}
. Having dealt with this in the past, I considered if casting it (object) array()
would be enough, but it appears to make no difference.
Do you know if there's some way to force the default to return as an object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is an aggravating issue and there isn't a great way to do it. What can be done is check if attributes
is empty in prepare_item_for_response
and set an empty object instead, but I really don't like that because it means that the attributes
property will sometimes be an array and sometimes be an object.
It is something I'd like to fix at some point, I'll try taking a look at this for 5.5.
Description
Add a simple REST API to allow get registered Block types.
How has this been tested?
The REST API request a logged in user to have
edit_post
capability.APIs
__experimental/block-types
List of all blocks__experimental/block-types/<namespace>/<block_type>
ie __experimental/block-types/core/post-author". Get details on a single block type__experimental/block-types/<namespace>
ie __experimental/block-types/core . Get all blocks in a single name space.fixes #2751
Trac ticket: #47620
Checklist: