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? https://github.com/WordPress/gutenberg/blob/master/docs/rfc/block-registration.md#block-api @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>
|
Would we plan to include unit tests here? Or later in the experimental lifecycle? |
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.
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.
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_postcapability.APIs
__experimental/block-typesList 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: