Skip to content

Commit

Permalink
Add missing field _invalid in menu item REST API (#34670)
Browse files Browse the repository at this point in the history
* Add missing field

* Lint

* Feedback.

* Fix tests.

* Fix lint
  • Loading branch information
spacedmonkey authored Sep 14, 2021
1 parent 8714f66 commit 4aaf626
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit 4aaf626

Please sign in to comment.