diff --git a/packages/block-library/src/navigation/map-menu-items-to-blocks.js b/packages/block-library/src/navigation/map-menu-items-to-blocks.js index 4b21aaa983881..3da4d7adca421 100644 --- a/packages/block-library/src/navigation/map-menu-items-to-blocks.js +++ b/packages/block-library/src/navigation/map-menu-items-to-blocks.js @@ -44,6 +44,14 @@ export const menuItemToBlockAttributes = ( { type: menuItemTypeField, target, } ) => { + // For historical reasons, the `core/navigation-link` variation type is `tag` + // 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 && { diff --git a/packages/edit-navigation/src/store/test/resolvers.js b/packages/edit-navigation/src/store/test/resolvers.js index fdbe8eddc97e5..eced25a0396f9 100644 --- a/packages/edit-navigation/src/store/test/resolvers.js +++ b/packages/edit-navigation/src/store/test/resolvers.js @@ -160,7 +160,6 @@ describe( 'getNavigationPostForMenu', () => { description: 'description', title: 'link title', kind: 'custom', - type: 'custom', }, clientId: 'client-id-0', innerBlocks: [], @@ -172,7 +171,6 @@ describe( 'getNavigationPostForMenu', () => { url: 'http://wp.org', opensInNewTab: true, kind: 'custom', - type: 'custom', }, clientId: 'client-id-1', innerBlocks: [], diff --git a/packages/edit-navigation/src/store/test/utils.js b/packages/edit-navigation/src/store/test/utils.js index 180b2b45f20f3..f03f096a983e2 100644 --- a/packages/edit-navigation/src/store/test/utils.js +++ b/packages/edit-navigation/src/store/test/utils.js @@ -851,7 +851,7 @@ describe( 'Mapping block attributes and menu item fields', () => { expect( actual ).toEqual( expect.objectContaining( { label: '', - type: 'custom', + url: '', kind: 'custom', } ) ); diff --git a/packages/edit-navigation/src/store/utils.js b/packages/edit-navigation/src/store/utils.js index 3d26c111ca4a2..ffa71c376e29c 100644 --- a/packages/edit-navigation/src/store/utils.js +++ b/packages/edit-navigation/src/store/utils.js @@ -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 &&