Skip to content

Commit

Permalink
Bring implementations of convert nav menu items to blocks back into s…
Browse files Browse the repository at this point in the history
…ync (#31602)

* Ensure post_tag case is covered in both implementations

* Bring implementation into line with Nav block implementation
  • Loading branch information
getdave authored May 10, 2021
1 parent f14962f commit ee8b5a3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
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`
// 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

0 comments on commit ee8b5a3

Please sign in to comment.