-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
Thanks for working on this. Looks like just the PHP Unit tests to update and this should be good to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this test be removed? It doesn't seem to trigger validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It failed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be better change the schema to make the min 1 and default 1.
gutenberg/lib/class-wp-rest-menu-items-controller.php
Lines 958 to 964 in 8e4ebfa
$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, | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also think about making the position a required field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Yes, let's do that instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Renamed the PR to be a little clearer as the title is what appears in the Gutenberg changelog. |
Please do not merge until this is resolved - #34672 (comment) |
…g into fix/remove-validation
@spacedmonkey, thanks for working on this. I see the following REST API response error when reordering menu items: Error
I think we should update
Current PHP Unit Tests failure also looks like to be related to the recent changes - https://github.com/WordPress/gutenberg/runs/3574827241. |
@adamziel @TimothyBJacobs @Mamaduka There seems to be some confusion here, on if we should not allow 'menu_order' => 0. Seems to lots of backwards and forwards on this one. According to this, 0 is not a validation position. I am not bother either way. I will defer to y'all on this one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's stick with as you have it now @spacedmonkey. I haven't tested the editor for regressions, but if all is working this looks good to merge to me.
Size Change: 0 B Total Size: 1.06 MB ℹ️ View Unchanged
|
* trunk: (74 commits) Update docs for ClipboardButton component (#34711) Post Title Block: add typography formatting options (#31623) Bump plugin version to 11.5.0 Navigation Screen: Adjust header toolbar icon styles (#34833) Fix the parent menu item field in REST API responses (#34835) Rewrite FocusableIframe as hook API (#26753) Create Block: Remove wp-cli callout since not recommended and outdated (#34821) Global Styles: Fix dimensions panel default controls display (#34828) [RNMobile][Embed block] Enable embed preview for Instagram and Vimeo providers (#34563) Increase Link UI search results to 10 on Nav Editor screen (#34808) Prevent welcome guide overflow x scroll (#34713) Enable open on click for Page List inside Navigation. (#34675) [RNMobile] [Embed block] - Unavailable preview fallback bottom sheet title update (#34674) Add missing field _invalid in menu item REST API (#34670) Fix Dropdown/DropdownMenu toggle closing in all UAs (#31170) Navigation submenu block: replace global shortcut event handlers with local ones (#34812) Navigation Screen: Consolidate menu name and switcher (#34786) Remove parent and position validation from menu item REST API endpoint (#34672) Clean theme data when switching themes in the customizer (#34540) Components: add reset timeout to ColorPicker's copy functionality. (#34601) ...
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:
*.native.js
files for terms that need renaming or removal).Fixes #25093