Skip to content

@drupal-js-sdk/menu

Overview

Fetches Drupal menu linkset and returns a normalized tree suitable for rendering. Also exposes helpers for validation and transformation.

Usage

JavaScript
import { Drupal } from "@drupal-js-sdk/core";
import { DrupalMenu } from "@drupal-js-sdk/menu";

const drupal = new Drupal({ baseURL: "https://example.com" });
const menu = new DrupalMenu(drupal);
const items = await menu.getMenu("main");

Public API

class DrupalMenu

Constructor

constructor(drupal: CoreInterface)

getMenu

getMenu(menuName: string): Promise<any[]>
Example
JavaScript
const items = await menu.getMenu("main");

getMenuRaw

getMenuRaw(menuName: string): Promise<any>

normalizeListItems

normalizeListItems(data: object): any[]

convertFlatListItemsToTree

convertFlatListItemsToTree(list: any[]): any[]

checkIfDrupalMenuDataIsValid

checkIfDrupalMenuDataIsValid(data?: object): boolean

Notes

  • Uses the HTTP client from CoreInterface and returns a normalized tree.