getMenu
Fetch a menu from Drupal.
⚠️
You need to install the JSON:API Menu Items module to use getMenu.
const resource = await drupal.getMenu<T = DrupalMenuItem>( menuName, options?: { params, withAuth, deserialize, locale, defaultLocale, withCache, cacheKey, }): Promise<{ items: T[] tree: T[]}>menuName: string- Required
- The name of the menu. Example:
mainorfooter.
options- Optional
params: JsonApiParams: JSON:API params such asfilter,fields,includeorsort.withAuth: boolean | NextDrupalAuth:- Set the authentication method to use. See the authentication docs.
- Set to
trueto use the authentication method configured on the client.
deserialize: boolean: Set to false to return the raw JSON:API response.locale: string: The locale to fetch the resource in.defaultLocale: string: The default locale of the site.withCache: boolean: SetwithCacheif you want to store and retrieve the menu from cache.cacheKey: string: The cache key to use.
Notes
getMenureturns:items: An array ofDrupalMenuItem.tree: An array ofDrupalMenuItemwith children nested to match the hierarchy from Drupal.
Examples
- Get the
mainmenu.
const { menu, items } = await drupal.getMenu("main")- Get the
mainmenu using cache.
const menu = await drupal.getMenu("main", { withCache: true, cacheKey: "menu--main",})