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

Bring implementations of convert nav menu items to blocks back into sync #31602

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export const menuItemToBlockAttributes = ( {
type: menuItemTypeField,
target,
} ) => {
// For historical reasons, the `core/navigation-link` variation type is `tag`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this got removed. It needs to match the editor's implementation.

// whereas WP Core expects `post_tag` as the `object` type.
// To avoid writing a block migration we perform a conversion here.
// See also inverse equivalent in `blockAttributesToMenuItem`.
if ( object && object === 'post_tag' ) {
object = 'tag';
}

return {
label: menuItemTitleField?.rendered || '',
...( object?.length && {
Expand Down
2 changes: 0 additions & 2 deletions packages/edit-navigation/src/store/test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ describe( 'getNavigationPostForMenu', () => {
description: 'description',
title: 'link title',
kind: 'custom',
type: 'custom',
},
clientId: 'client-id-0',
innerBlocks: [],
Expand All @@ -172,7 +171,6 @@ describe( 'getNavigationPostForMenu', () => {
url: 'http://wp.org',
opensInNewTab: true,
kind: 'custom',
type: 'custom',
},
clientId: 'client-id-1',
innerBlocks: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-navigation/src/store/test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ describe( 'Mapping block attributes and menu item fields', () => {
expect( actual ).toEqual(
expect.objectContaining( {
label: '',
type: 'custom',
url: '',
kind: 'custom',
} )
);
Expand Down
4 changes: 3 additions & 1 deletion packages/edit-navigation/src/store/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,9 @@ export const menuItemToBlockAttributes = ( {

return {
label: menuItemTitleField?.rendered || '',
type: object || 'custom',
...( object?.length && {
type: object,
} ),
kind: menuItemTypeField?.replace( '_', '-' ) || 'custom',
url: url || '',
...( xfn?.length &&
Expand Down