DruxtMenu (druxt-menu)
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.
| Param | Type | Description |
|---|---|---|
| baseUrl | string | The URL of the Drupal backend. |
| options | ModuleOptions | The 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
| Param | Type | Description |
|---|---|---|
| menuName | string | The menu name. |
| settings | object | The Druxt Menu query settings object. |
| prefix | string | (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
| Param | Type | Description |
|---|---|---|
| menuName | string | The menu name. |
| settings | object | The Druxt Menu query settings object. |
| prefix | string | (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 thejsonApiMenuItemsoption is set.
Kind: instance method of DruxtMenu
See: JSON:API Menu Items
| Param | Type | Description |
|---|---|---|
| menuName | string | The menu name. |
| settings | object | The Druxt Menu query settings object. |
| prefix | string | (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