diff --git a/docs/reference-guides/data/data-core.md b/docs/reference-guides/data/data-core.md index 2c92e1b0e641e..e3b0a9ea5c00b 100644 --- a/docs/reference-guides/data/data-core.md +++ b/docs/reference-guides/data/data-core.md @@ -341,6 +341,10 @@ _Returns_ - `EntityRecordKey | undefined`: The ID for the fallback Navigation post. +### getNavigationMenu + +Undocumented declaration. + ### getNavigationMenuBySlug Returns a Navigation Menu object by slug. diff --git a/packages/core-data/README.md b/packages/core-data/README.md index a1506396aa1c5..5b36c892671f8 100644 --- a/packages/core-data/README.md +++ b/packages/core-data/README.md @@ -518,6 +518,10 @@ _Returns_ - `EntityRecordKey | undefined`: The ID for the fallback Navigation post. +### getNavigationMenu + +Undocumented declaration. + ### getNavigationMenuBySlug Returns a Navigation Menu object by slug. diff --git a/packages/core-data/src/resolvers.js b/packages/core-data/src/resolvers.js index bcaa01e28c7c0..11b81509c9458 100644 --- a/packages/core-data/src/resolvers.js +++ b/packages/core-data/src/resolvers.js @@ -600,10 +600,16 @@ export const getNavigationFallbackId = } }; +export const getNavigationMenu = + ( id ) => + async ( { resolveSelect } ) => { + resolveSelect.getEntityRecord( 'postType', 'wp_navigation', id ); + }; + export const getNavigationMenuBySlug = ( slug ) => async ( { resolveSelect } ) => { - await resolveSelect.getEntityRecords( 'postType', 'wp_navigation', { + resolveSelect.getEntityRecords( 'postType', 'wp_navigation', { slug, per_page: 1, } ); diff --git a/packages/core-data/src/selectors.ts b/packages/core-data/src/selectors.ts index dd1948c97ff3e..93ed90ebe4495 100644 --- a/packages/core-data/src/selectors.ts +++ b/packages/core-data/src/selectors.ts @@ -1269,6 +1269,19 @@ export function getCurrentThemeGlobalStylesRevisions( return state.themeGlobalStyleRevisions[ currentGlobalStylesId ]; } +export function getNavigationMenu( + state: State, + id: EntityRecordKey +): Object | null { + const record = getEntityRecord( state, 'postType', 'wp_navigation', id ); + + if ( ! record ) { + return null; + } + + return record; +} + /** * Returns a Navigation Menu object by slug. *