-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Font Library: Improve font collection rest controller #58222
Font Library: Improve font collection rest controller #58222
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/experimental/fonts/font-library/class-wp-font-collection.php ❔ lib/experimental/fonts/font-library/class-wp-font-library.php ❔ lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php ❔ phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php |
Size Change: +2.23 kB (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
Flaky tests detected in 6a5971c. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7646662678
|
Another small improvement that would be good to get into this PR: https://github.com/WordPress/gutenberg/pull/57688/files/dde20599cc947557569499dc161d5e71412b6d88#r1465558856 |
👍 Added in 18f9963 |
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.
This is testing well for me:
- Run unit tests ✅
- Font collection functionality still works as expected, both success and errors ✅
It looks like the unit tests could be expanded to include the new pagination functionality, but maybe this could happen in a follow-up.
lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Sarah Norris <[email protected]>
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.
Left a couple of minor code suggestions. Will test functionality next.
lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-font-collection.php
Outdated
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php
Show resolved
Hide resolved
Co-authored-by: Grant Kinney <[email protected]>
} | ||
} | ||
|
||
return rest_ensure_response( $item ); |
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 think we also need to add links, including a prepare_links method for the controller.
return rest_ensure_response( $item ); | |
$response = rest_ensure_response( $item ); | |
if ( rest_is_field_included( '_links', $fields ) ) { | |
$links = $this->prepare_links( $collection ); | |
$response->add_links( $links ); | |
} | |
/** | |
* Filters the collection data for a REST API response. | |
* | |
* @since 6.5.0 | |
* | |
* @param WP_REST_Response $response The response object. | |
* @param WP_Font_Collection $collection Font Collection object. | |
* @param WP_REST_Request $request. Request object. | |
*/ | |
return apply_filters( "rest_prepare_font_collection", $response, $collection, $request ); |
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.
added here: 7372ddc
lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php
Show resolved
Hide resolved
lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php
Show resolved
Hide resolved
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.
This is testing well for me:
_fields
param works as expected to limit returned fields.per_page
andpage
params work to return paginated results, including correct headers (matches wp/v2/posts endpoint behavior)
I see a few more things to add to make this complete regarding _links and the context param, see specific comments.
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.
This is working well for me, I tested
- pagination using
per_page
andpage
params - _fields param returning only specified fields
- Seeing _links by default in the responses
- context param works as expected, with view being the default, and is defined in the schema
* @param WP_REST_Response $response The response object. | ||
* @param WP_Font_Collection $collection The Font Collection object. | ||
* @param WP_REST_Request $request Request used to generate the response. |
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.
Nitpick: the variable names and descriptions should be aligned.
* make WP_Font_Collection object properties public * remove class method no longer used * simplify the acces to the font collection properties * add schema, args, fields and pagination to font collections rest controller * add one test case for params * request a subset of font collection fields * lint * remove not needed default change * update version since * use placeholder for translation * update comment Co-authored-by: Sarah Norris <[email protected]> * update translation domain Co-authored-by: Grant Kinney <[email protected]> * update wording * set context to edit only * use 'view', 'edit' and 'embed' on the context of all the schema properties * prepare_item_for_response * default context param * args for item endpoint * format php --------- Co-authored-by: Sarah Norris <[email protected]> Co-authored-by: Grant Kinney <[email protected]>
I just cherry-picked this PR to the release/17.6 branch to get it included in the next release: 0975924 |
* make WP_Font_Collection object properties public * remove class method no longer used * simplify the acces to the font collection properties * add schema, args, fields and pagination to font collections rest controller * add one test case for params * request a subset of font collection fields * lint * remove not needed default change * update version since * use placeholder for translation * update comment Co-authored-by: Sarah Norris <[email protected]> * update translation domain Co-authored-by: Grant Kinney <[email protected]> * update wording * set context to edit only * use 'view', 'edit' and 'embed' on the context of all the schema properties * prepare_item_for_response * default context param * args for item endpoint * format php --------- Co-authored-by: Sarah Norris <[email protected]> Co-authored-by: Grant Kinney <[email protected]>
What?
font_families
orcategories
are requested.Why?
How?
Changing the REST controller.
Testing Instructions