Make WordPress Core

Changeset 56297 for branches/6.3


Ignore:
Timestamp:
07/25/2023 06:33:12 AM (3 years ago)
Author:
isabel_brison
Message:

Editor: load title on navigation fallback.

Adds raw title property when loading the navigation fallback with an embed context.

Props ramonopoly, get_dave, scruffian, mukesh27, audrasjb.
Reviewed by audrasjb.
Merges [56296] to the 6.3 branch.
See #58557.

Location:
branches/6.3
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/6.3

  • branches/6.3/src/wp-includes/navigation-fallback.php

    r56052 r56297  
    1414 *
    1515 * The endpoint may embed the full Navigation Menu object into the
    16  * response as the `self` link. By default the Posts Controller
    17  * will only exposes a limited subset of fields but the editor requires
    18  * additional fields to be available in order to utilise the menu.
     16 * response as the `self` link. By default, the Posts Controller
     17 * will only expose a limited subset of fields but the editor requires
     18 * additional fields to be available in order to utilize the menu.
    1919 *
    2020 * @since 6.3.0
    … …  
    2323 * @return array the modified schema.
    2424 */
    25 function wp_add_fields_to_navigation_fallback_embeded_links( $schema ) {
     25function wp_add_fields_to_navigation_fallback_embedded_links( $schema ) {
    2626        // Expose top level fields.
    2727        $schema['properties']['status']['context']  = array_merge( $schema['properties']['status']['context'], array( 'embed' ) );
    2828        $schema['properties']['content']['context'] = array_merge( $schema['properties']['content']['context'], array( 'embed' ) );
    2929
    30         // Expose sub properties of content field.
     30        /*
     31         * Exposes sub properties of content field.
     32         * These sub properties aren't exposed by the posts controller by default,
     33         * for requests where context is `embed`.
     34         *
     35         * @see WP_REST_Posts_Controller::get_item_schema()
     36         */
    3137        $schema['properties']['content']['properties']['raw']['context']           = array_merge( $schema['properties']['content']['properties']['raw']['context'], array( 'embed' ) );
    3238        $schema['properties']['content']['properties']['rendered']['context']      = array_merge( $schema['properties']['content']['properties']['rendered']['context'], array( 'embed' ) );
    3339        $schema['properties']['content']['properties']['block_version']['context'] = array_merge( $schema['properties']['content']['properties']['block_version']['context'], array( 'embed' ) );
     40
     41        /*
     42         * Exposes sub properties of title field.
     43         * These sub properties aren't exposed by the posts controller by default,
     44         * for requests where context is `embed`.
     45         *
     46         * @see WP_REST_Posts_Controller::get_item_schema()
     47         */
     48        $schema['properties']['title']['properties']['raw']['context'] = array_merge( $schema['properties']['title']['properties']['raw']['context'], array( 'embed' ) );
    3449
    3550        return $schema;
    … …  
    3853add_filter(
    3954        'rest_wp_navigation_item_schema',
    40         'wp_add_fields_to_navigation_fallback_embeded_links'
     55        'wp_add_fields_to_navigation_fallback_embedded_links'
    4156);
  • branches/6.3/src/wp-settings.php

    r56241 r56297  
    348348require ABSPATH . WPINC . '/block-supports/typography.php';
    349349require ABSPATH . WPINC . '/block-supports/settings.php';
     350require ABSPATH . WPINC . '/navigation-fallback.php';
    350351require ABSPATH . WPINC . '/style-engine.php';
    351352require ABSPATH . WPINC . '/style-engine/class-wp-style-engine.php';
  • branches/6.3/tests/phpunit/tests/rest-api/rest-navigation-fallback-controller.php

    r56052 r56297  
    142142
    143143                $this->assertTrue( $links['self'][0]['attributes']['embeddable'], 'Self link should be embeddable.' );
     144        }
     145
     146        /**
     147         * Tests that the correct filters are applied to the context parameter.
     148         *
     149         * By default, the REST response for the Posts Controller will not return all fields
     150         * when the context is set to 'embed'. Assert that correct additional fields are added
     151         * to the embedded Navigation Post, when the navigation fallback endpoint
     152         * is called with the `_embed` param.
     153         *
     154         * @ticket 58557
     155         *
     156         * @covers wp_add_fields_to_navigation_fallback_embedded_links
     157         *
     158         * @since 6.3.0 Added Navigation Fallbacks endpoint.
     159         */
     160        public function test_embedded_navigation_post_contains_required_fields() {
     161                // First we'll use the navigation fallback to get a link to the navigation endpoint.
     162                $request  = new WP_REST_Request( 'GET', '/wp-block-editor/v1/navigation-fallback' );
     163                $response = rest_get_server()->dispatch( $request );
     164                $links    = $response->get_links();
     165
     166                // Extract the navigation endpoint URL from the response.
     167                $embedded_navigation_href = $links['self'][0]['href'];
     168                preg_match( '/\?rest_route=(.*)/', $embedded_navigation_href, $matches );
     169                $navigation_endpoint = $matches[1];
     170
     171                // Fetch the "linked" navigation post from the endpoint, with the context parameter set to 'embed' to simulate fetching embedded links.
     172                $request = new WP_REST_Request( 'GET', $navigation_endpoint );
     173                $request->set_param( 'context', 'embed' );
     174                $response = rest_get_server()->dispatch( $request );
     175                $data     = $response->get_data();
     176
     177                // Verify that the additional status field is present.
     178                $this->assertArrayHasKey( 'status', $data, 'Response title should contain a "status" field.' );
     179
     180                // Verify that the additional content fields are present.
     181                $this->assertArrayHasKey( 'content', $data, 'Response should contain a "content" field.' );
     182                $this->assertArrayHasKey( 'raw', $data['content'], 'Response content should contain a "raw" field.' );
     183                $this->assertArrayHasKey( 'rendered', $data['content'], 'Response content should contain a "rendered" field.' );
     184                $this->assertArrayHasKey( 'block_version', $data['content'], 'Response should contain a "block_version" field.' );
     185
     186                // Verify that the additional title.raw field is present.
     187                $this->assertArrayHasKey( 'raw', $data['title'], 'Response title should contain a "raw" key.' );
    144188        }
    145189
  • branches/6.3/tests/qunit/fixtures/wp-api-generated.js

    r56082 r56297  
    66836683                                    "type": "string",
    66846684                                    "context": [
    6685                                         "edit"
     6685                                        "edit",
     6686                                        "embed"
    66866687                                    ]
    66876688                                },
    … …  
    67076708                                    "type": "string",
    67086709                                    "context": [
    6709                                         "edit"
     6710                                        "edit",
     6711                                        "embed"
    67106712                                    ]
    67116713                                },
    … …  
    67156717                                    "context": [
    67166718                                        "view",
    6717                                         "edit"
     6719                                        "edit",
     6720                                        "embed"
    67186721                                    ],
    67196722                                    "readonly": true
    … …  
    67236726                                    "type": "integer",
    67246727                                    "context": [
    6725                                         "edit"
     6728                                        "edit",
     6729                                        "embed"
    67266730                                    ],
    67276731                                    "readonly": true
    … …  
    68606864                                    "type": "string",
    68616865                                    "context": [
    6862                                         "edit"
     6866                                        "edit",
     6867                                        "embed"
    68636868                                    ]
    68646869                                },
    … …  
    68846889                                    "type": "string",
    68856890                                    "context": [
    6886                                         "edit"
     6891                                        "edit",
     6892                                        "embed"
    68876893                                    ]
    68886894                                },
    … …  
    68926898                                    "context": [
    68936899                                        "view",
    6894                                         "edit"
     6900                                        "edit",
     6901                                        "embed"
    68956902                                    ],
    68966903                                    "readonly": true
    … …  
    69006907                                    "type": "integer",
    69016908                                    "context": [
    6902                                         "edit"
     6909                                        "edit",
     6910                                        "embed"
    69036911                                    ],
    69046912                                    "readonly": true
    … …  
    71937201                                    "type": "string",
    71947202                                    "context": [
    7195                                         "edit"
     7203                                        "edit",
     7204                                        "embed"
    71967205                                    ]
    71977206                                },
    … …  
    72177226                                    "type": "string",
    72187227                                    "context": [
    7219                                         "edit"
     7228                                        "edit",
     7229                                        "embed"
    72207230                                    ]
    72217231                                },
    … …  
    72257235                                    "context": [
    72267236                                        "view",
    7227                                         "edit"
     7237                                        "edit",
     7238                                        "embed"
    72287239                                    ],
    72297240                                    "readonly": true
    … …  
    72337244                                    "type": "integer",
    72347245                                    "context": [
    7235                                         "edit"
     7246                                        "edit",
     7247                                        "embed"
    72367248                                    ],
    72377249                                    "readonly": true
Note: See TracChangeset for help on using the changeset viewer.