Skip to content
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

Add missing field _invalid in menu item REST API #34670

Merged
merged 7 commits into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/class-wp-rest-menu-items-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,10 @@ public function prepare_item_for_response( $post, $request ) {
$data['xfn'] = array_map( 'sanitize_html_class', explode( ' ', $menu_item->xfn ) );
}

if ( rest_is_field_included( 'invalid', $fields ) ) {
$data['invalid'] = (bool) $menu_item->_invalid;
}

if ( rest_is_field_included( 'meta', $fields ) ) {
$data['meta'] = $this->meta->get_value( $menu_item->ID, $request );
}
Expand Down Expand Up @@ -1007,7 +1011,7 @@ public function get_item_schema() {
),
);

$schema['properties']['_invalid'] = array(
$schema['properties']['invalid'] = array(
'description' => __( 'Whether the menu item represents an object that no longer exists.', 'gutenberg' ),
'context' => array( 'view', 'edit', 'embed' ),
'type' => 'boolean',
Expand Down
4 changes: 3 additions & 1 deletion phpunit/class-rest-nav-menu-items-controller-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ public function test_get_item_schema() {
$this->assertArrayHasKey( 'title', $properties );
$this->assertArrayHasKey( 'type', $properties );
$this->assertArrayHasKey( 'xfn', $properties );
$this->assertArrayHasKey( '_invalid', $properties );
$this->assertArrayHasKey( 'invalid', $properties );
}

/**
Expand Down Expand Up @@ -792,6 +792,8 @@ protected function check_menu_item_data( $post, $data, $context, $links ) {
$this->assertEmpty( $data['parent'] );
}

$this->assertFalse( $data['invalid'] );

// page attributes.
$this->assertEquals( $post->menu_order, $data['menu_order'] );

Expand Down