Skip to content

Drupal Menu and Menu item Druxt components, with support for the JSON:API Menu Items module.

DruxtMenu (druxt-menu)

View source on GitHub

DruxtMenu

DruxtMenu class.

Provides methods for accessing Menu items from the Drupal JSON:API.

Kind: global class
See: /modules/menu


new DruxtMenu(baseUrl, options)

DruxtMenu constructor.

  • Validates module options.
  • Sets up a DruxtRouter instance.
ParamTypeDescription
baseUrlstringThe URL of the Drupal backend.
optionsModuleOptionsThe module options.

Example

const druxtMenu = new DruxtMenu('https://example.com', {})

.druxt : DruxtClient

Instance of the Druxt Client.

Kind: instance property of DruxtMenu
See: DruxtClient


.get(menuName, settings, prefix)

Gets the menu items JSON:API resources using the configured method.

Kind: instance method of DruxtMenu

ParamTypeDescription
menuNamestringThe menu name.
settingsobjectThe Druxt Menu query settings object.
prefixstring(Optional) The JSON:API endpoint prefix or langcode.

Example

const menu = await druxtMenu.get('main')

.getMenuLinkContent(menuName, settings, prefix)

Gets a menus 'menu_link_content' JSON:API resources.

  • This method can only retrieve user created menu items.
  • This is the default method for the get() method.

Kind: instance method of DruxtMenu

ParamTypeDescription
menuNamestringThe menu name.
settingsobjectThe Druxt Menu query settings object.
prefixstring(Optional) The JSON:API endpoint prefix or langcode.

Example

const menu = await druxtMenu.getMenuLinkContent('menu')

.getJsonApiMenuItems(menuName, settings, prefix)

Gets menu items via the Drupal JSON:API Menu Items module.

  • This method gets all menu items, but requires the JSON:API Menu Items module.
  • This method is used by the get() method when the jsonApiMenuItems option is set.

Kind: instance method of DruxtMenu
See: JSON:API Menu Items

ParamTypeDescription
menuNamestringThe menu name.
settingsobjectThe Druxt Menu query settings object.
prefixstring(Optional) The JSON:API endpoint prefix or langcode.

Example

const menu = await druxtMenu.getJsonApiMenuItems(
  'menu',
  {
    requiredOnly: true,
  }
)

ModuleOptions : object

Module options.

Kind: global typedef
See: ModuleOptions