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

Remove parent and position validation from menu item REST API endpoint #34672

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from

Conversation

@spacedmonkey
Copy link
Member

@spacedmonkey spacedmonkey commented Sep 8, 2021

Description

As noted in #25093 (comment), we need to remove this validation, so that we can make batch requests work. This PR is simple, remove validation for parent and position.

How has this been tested?

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

Fixes #25093

@talldan
Copy link
Contributor

@talldan talldan commented Sep 9, 2021

Thanks for working on this. Looks like just the PHP Unit tests to update and this should be good to go.

Copy link
Contributor

@talldan talldan left a comment

Thanks! I tested alongside @adamziel's PR for making the nav editor use the REST API #34541, and reordering is working well.

public function test_create_item_change_position() {
wp_set_current_user( self::$admin_id );
$new_menu_id = wp_create_nav_menu( rand_str() );
for ( $i = 1; $i < 5; $i ++ ) {
$request = new WP_REST_Request( 'POST', '/__experimental/menu-items' );
$request->add_header( 'content-type', 'application/x-www-form-urlencoded' );
$params = $this->set_menu_item_data(
array(
'menus' => $new_menu_id,
)
);
$request->set_body_params( $params );
$response = rest_get_server()->dispatch( $request );
$this->check_create_menu_item_response( $response );
$data = $response->get_data();
$this->assertEquals( $data['menu_order'], $i );
}
}
Comment on lines 277 to 294

This comment has been minimized.

@talldan

talldan Sep 10, 2021
Contributor

Should this test be removed? It doesn't seem to trigger validation.

This comment has been minimized.

@spacedmonkey

spacedmonkey Sep 10, 2021
Author Member

It failed.

This comment has been minimized.

@adamziel

adamziel Sep 10, 2021
Contributor

It failed because it resulted in the following sequence of positions: 0, 2, 3, 4, 5. According to https://core.trac.wordpress.org/ticket/28140, menu position 0 is invalid and breaks things so it would be good to get it fixed. I proposed an adjustment in 4e97c84 (feel free to roll it back) – what do you think @spacedmonkey ?

This comment has been minimized.

@spacedmonkey

spacedmonkey Sep 10, 2021
Author Member

I think it might be better change the schema to make the min 1 and default 1.

$schema['properties']['menu_order'] = array(
'description' => __( 'The DB ID of the nav_menu_item that is this item\'s menu parent, if any, otherwise 0.', 'gutenberg' ),
'context' => array( 'view', 'edit', 'embed' ),
'type' => 'integer',
'minimum' => 0,
'default' => 0,
);

This comment has been minimized.

@spacedmonkey

spacedmonkey Sep 10, 2021
Author Member

I would also think about making the position a required field.

This comment has been minimized.

@adamziel

adamziel Sep 10, 2021
Contributor

Nice! Yes, let's do that instead

@talldan talldan changed the title Remove validation Remove parent and position validation from menu item REST API endpoint Sep 10, 2021
@talldan
Copy link
Contributor

@talldan talldan commented Sep 10, 2021

Renamed the PR to be a little clearer as the title is what appears in the Gutenberg changelog.

@spacedmonkey spacedmonkey requested a review from adamziel Sep 10, 2021
@spacedmonkey
Copy link
Member Author

@spacedmonkey spacedmonkey commented Sep 10, 2021

Please do not merge until this is resolved - #34672 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment