diff --git a/packages/block-library/src/navigation-link/edit.js b/packages/block-library/src/navigation-link/edit.js index 0348ec76cfd31d..91e76d905b0403 100644 --- a/packages/block-library/src/navigation-link/edit.js +++ b/packages/block-library/src/navigation-link/edit.js @@ -289,9 +289,10 @@ export default function NavigationLinkEdit( { return { id: page.id, - postType, + type: postType, title: page.title.rendered, url: page.link, + kind: 'post-type', }; } @@ -513,6 +514,8 @@ export default function NavigationLinkEdit( { url: newURL = '', opensInNewTab: newOpensInNewTab, id, + kind: newKind = '', + type: newType = '', } = {} ) => setAttributes( { url: encodeURI( newURL ), @@ -540,6 +543,14 @@ export default function NavigationLinkEdit( { } )(), opensInNewTab: newOpensInNewTab, id, + ...( newKind && { + kind: newKind, + } ), + ...( newType && + newType !== 'URL' && + newType !== 'post-format' && { + type: newType, + } ), } ) } /> diff --git a/packages/block-library/src/navigation-link/fallback-variations.js b/packages/block-library/src/navigation-link/fallback-variations.js index 1214102801922c..5f8d44702a1157 100644 --- a/packages/block-library/src/navigation-link/fallback-variations.js +++ b/packages/block-library/src/navigation-link/fallback-variations.js @@ -26,28 +26,28 @@ const fallbackVariations = [ icon: postIcon, title: __( 'Post Link' ), description: __( 'A link to a post.' ), - attributes: { type: 'post' }, + attributes: { type: 'post', kind: 'post-type' }, }, { name: 'page', icon: pageIcon, title: __( 'Page Link' ), description: __( 'A link to a page.' ), - attributes: { type: 'page' }, + attributes: { type: 'page', kind: 'post-type' }, }, { name: 'category', icon: categoryIcon, title: __( 'Category Link' ), description: __( 'A link to a category.' ), - attributes: { type: 'category' }, + attributes: { type: 'category', kind: 'taxonomy' }, }, { name: 'tag', icon: tagIcon, title: __( 'Tag Link' ), description: __( 'A link to a tag.' ), - attributes: { type: 'tag' }, + attributes: { type: 'tag', kind: 'taxonomy' }, }, ]; diff --git a/packages/block-library/src/navigation-link/test/__snapshots__/hooks.js.snap b/packages/block-library/src/navigation-link/test/__snapshots__/hooks.js.snap index dc1669c095e524..93ed87117d9355 100644 --- a/packages/block-library/src/navigation-link/test/__snapshots__/hooks.js.snap +++ b/packages/block-library/src/navigation-link/test/__snapshots__/hooks.js.snap @@ -17,6 +17,7 @@ Object { }, Object { "attributes": Object { + "kind": "post-type", "type": "post", }, "description": "A link to a post.", @@ -34,6 +35,7 @@ Object { }, Object { "attributes": Object { + "kind": "post-type", "type": "page", }, "description": "A link to a page.", @@ -51,6 +53,7 @@ Object { }, Object { "attributes": Object { + "kind": "taxonomy", "type": "category", }, "description": "A link to a category.", @@ -70,6 +73,7 @@ Object { }, Object { "attributes": Object { + "kind": "taxonomy", "type": "tag", }, "description": "A link to a tag.", diff --git a/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js index ef1a80c95c2437..10252f736bb2ff 100644 --- a/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js +++ b/packages/core-data/src/fetch/__experimental-fetch-link-suggestions.js @@ -12,6 +12,12 @@ import { __ } from '@wordpress/i18n'; * @typedef { 'post' | 'term' | 'post-format' } WPLinkSearchType */ +/** + * A link with an id may be of kind post-type or taxonomy + * + * @typedef { 'post-type' | 'taxonomy' } WPKind + */ + /** * @typedef WPLinkSearchOptions * @@ -29,6 +35,7 @@ import { __ } from '@wordpress/i18n'; * @property {string} url Link url. * @property {string} title Title of the link. * @property {string} type The taxonomy or post type slug or type URL. + * @property {WPKind} [kind] Link kind of post-type or taxonomy */ /** @@ -87,7 +94,16 @@ const fetchLinkSuggestions = async ( type: 'post', subtype, } ), - } ).catch( () => [] ) // fail by returning no results + } ) + .then( ( results ) => { + return results.map( ( result ) => { + return { + ...result, + meta: { kind: 'post-type', subtype }, + }; + } ); + } ) + .catch( () => [] ) // fail by returning no results ); } @@ -101,7 +117,16 @@ const fetchLinkSuggestions = async ( type: 'term', subtype, } ), - } ).catch( () => [] ) + } ) + .then( ( results ) => { + return results.map( ( result ) => { + return { + ...result, + meta: { kind: 'taxonomy', subtype }, + }; + } ); + } ) + .catch( () => [] ) ); } @@ -146,6 +171,7 @@ const fetchLinkSuggestions = async ( decodeEntities( result.title || '' ) || __( '(no title)' ), type: result.subtype || result.type, + kind: result?.meta?.kind, }; } ); diff --git a/packages/core-data/src/fetch/test/__experimental-fetch-link-suggestions.js b/packages/core-data/src/fetch/test/__experimental-fetch-link-suggestions.js index 82a68cc7974396..5270b43cfc082c 100644 --- a/packages/core-data/src/fetch/test/__experimental-fetch-link-suggestions.js +++ b/packages/core-data/src/fetch/test/__experimental-fetch-link-suggestions.js @@ -93,6 +93,7 @@ describe( 'fetchLinkSuggestions', () => { title: 'Contact Page', type: 'page', url: 'http://wordpress.local/contact-page/', + kind: 'post-type', }, ] ) ); @@ -108,12 +109,14 @@ describe( 'fetchLinkSuggestions', () => { title: 'Cats', url: 'http://wordpress.local/category/cats/', type: 'category', + kind: 'taxonomy', }, { id: 1, title: 'Uncategorized', url: 'http://wordpress.local/category/uncategorized/', type: 'category', + kind: 'taxonomy', }, ] ) ); @@ -155,18 +158,21 @@ describe( 'fetchLinkSuggestions', () => { title: 'Contact Page', url: 'http://wordpress.local/contact-page/', type: 'page', + kind: 'post-type', }, { id: 9, title: 'Cats', url: 'http://wordpress.local/category/cats/', type: 'category', + kind: 'taxonomy', }, { id: 1, title: 'Uncategorized', url: 'http://wordpress.local/category/uncategorized/', type: 'category', + kind: 'taxonomy', }, { id: 'gallery', @@ -195,6 +201,7 @@ describe( 'fetchLinkSuggestions', () => { title: 'Limit Case', url: 'http://wordpress.local/limit-case/', type: 'page', + kind: 'post-type', }, ] ) ); @@ -211,6 +218,7 @@ describe( 'fetchLinkSuggestions', () => { title: 'Page Case', url: 'http://wordpress.local/page-case/', type: 'page', + kind: 'post-type', }, ] ) ); diff --git a/packages/e2e-tests/specs/experiments/blocks/__snapshots__/navigation.test.js.snap b/packages/e2e-tests/specs/experiments/blocks/__snapshots__/navigation.test.js.snap index de0c4f8531459b..74860922357e8d 100644 --- a/packages/e2e-tests/specs/experiments/blocks/__snapshots__/navigation.test.js.snap +++ b/packages/e2e-tests/specs/experiments/blocks/__snapshots__/navigation.test.js.snap @@ -48,12 +48,12 @@ exports[`Navigation allows an empty navigation block to be created and manually " - + " `; exports[`Navigation allows pages to be created from the navigation block and their links added to menu 1`] = ` " - + " `;