Skip to content

Commit

Permalink
Backporting changes from WordPress/wordpress-develop#4891 (#52878)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd authored Jul 24, 2023
1 parent b2309e8 commit e05e038
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
30 changes: 19 additions & 11 deletions lib/compat/wordpress-6.3/navigation-fallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,42 @@
* Navigation Fallback REST endpoint.
*
* The endpoint may embed the full Navigation Menu object into the
* response as the `self` link. By default the Posts Controller
* will only exposes a limited subset of fields but the editor requires
* additional fields to be available in order to utilise the menu.
* response as the `self` link. By default, the Posts Controller
* will only expose a limited subset of fields but the editor requires
* additional fields to be available in order to utilize the menu.
*
* @param array $schema the schema for the `wp_navigation` post.
* @return array the modified schema.
*/
function gutenberg_add_fields_to_navigation_fallback_embeded_links( $schema ) {
function gutenberg_add_fields_to_navigation_fallback_embedded_links( $schema ) {
// Expose top level fields.
$schema['properties']['status']['context'] = array_merge( $schema['properties']['status']['context'], array( 'embed' ) );
$schema['properties']['content']['context'] = array_merge( $schema['properties']['content']['context'], array( 'embed' ) );

// Expose sub properties of content field.
// These aren't exposed by the posts controller by default, see:
// https://github.com/WordPress/wordpress-develop/blob/5c3c6258e468c67ba00bbd13db29994f1a57a52a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2425.
/*
* Exposes sub properties of content field.
* These sub properties aren't exposed by the posts controller by default,
* for requests where context is `embed`.
*
* @see WP_REST_Posts_Controller::get_item_schema()
*/
$schema['properties']['content']['properties']['raw']['context'] = array_merge( $schema['properties']['content']['properties']['raw']['context'], array( 'embed' ) );
$schema['properties']['content']['properties']['rendered']['context'] = array_merge( $schema['properties']['content']['properties']['rendered']['context'], array( 'embed' ) );
$schema['properties']['content']['properties']['block_version']['context'] = array_merge( $schema['properties']['content']['properties']['block_version']['context'], array( 'embed' ) );

// Expose sub properties of title field.
// These aren't exposed by the posts controller by default, see:
// https://github.com/WordPress/wordpress-develop/blob/5c3c6258e468c67ba00bbd13db29994f1a57a52a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php#L2401.
/*
* Exposes sub properties of title field.
* These sub properties aren't exposed by the posts controller by default,
* for requests where context is `embed`.
*
* @see WP_REST_Posts_Controller::get_item_schema()
*/
$schema['properties']['title']['properties']['raw']['context'] = array_merge( $schema['properties']['title']['properties']['raw']['context'], array( 'embed' ) );

return $schema;
}

add_filter(
'rest_wp_navigation_item_schema',
'gutenberg_add_fields_to_navigation_fallback_embeded_links'
'gutenberg_add_fields_to_navigation_fallback_embedded_links'
);
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public function test_prepare_item() {
* to the embedded Navigation Post, when the navigation fallback endpoint
* is called with the `_embed` param.
*
* @covers wp_add_fields_to_navigation_fallback_embeded_links
* @covers wp_add_fields_to_navigation_fallback_embedded_links
*/
public function test_embedded_navigation_post_contains_required_fields() {
// First we'll use the navigation fallback to get a link to the navigation endpoint.
Expand Down

1 comment on commit e05e038

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in e05e038.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5650973189
📝 Reported issues:

Please sign in to comment.