mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-04 17:20:07 +00:00
Editor: Move wp_navigation schema updating to WP_Navigation_Fallback class.
This aims to better align the navigation fallback implementation with core architecture and best practices. The function that updates the `wp_navigation` post response schema is now a public method of the `WP_Navigation_Fallback` class, so an extra file previously used for that specific function is no longer necessary. Follow-up to [56052]. Props ramonopoly, scruffian, isabel_brison, mukesh27, swissspidy, rajinsharwar, afercia, audrasjb, mikeschroder, JeffPaul, johnjamesjacoby, TimothyBlynJacobs, oglekler, SergeyBiryukov. Fixes #58910. git-svn-id: https://develop.svn.wordpress.org/trunk@56793 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -17,6 +17,50 @@
|
||||
*/
|
||||
class WP_Navigation_Fallback {
|
||||
|
||||
/**
|
||||
* Updates the wp_navigation custom post type schema, in order to expose
|
||||
* additional fields in the embeddable links of WP_REST_Navigation_Fallback_Controller.
|
||||
*
|
||||
* The Navigation Fallback endpoint may embed the full Navigation Menu object
|
||||
* into the 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.
|
||||
*
|
||||
* Used with the `rest_wp_navigation_item_schema` hook.
|
||||
*
|
||||
* @since 6.4.0
|
||||
*
|
||||
* @param array $schema The schema for the `wp_navigation` post.
|
||||
* @return array The modified schema.
|
||||
*/
|
||||
public static function update_wp_navigation_post_schema( $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' ) );
|
||||
|
||||
/*
|
||||
* 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' ) );
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets (and/or creates) an appropriate fallback Navigation Menu.
|
||||
*
|
||||
@@ -25,7 +69,6 @@ class WP_Navigation_Fallback {
|
||||
* @return WP_Post|null the fallback Navigation Post or null.
|
||||
*/
|
||||
public static function get_fallback() {
|
||||
|
||||
/**
|
||||
* Filters whether or not a fallback should be created.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user