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

The DruxtMenu component renders a Drupal menu using menu link content entities via the core JSON:API (content-created links only), or the complete menu tree, including module-defined links, via the JSON:API Menu Items module.

See: Component resolution
Example

<DruxtMenu name="main" />

Example (DruxtMenu Wrapper component boilerplate)

<template>
  <DruxtDebug :json="items" />
</template>

<script>
import { DruxtMenuMixin } from 'druxt-menu'
export default {
  mixins: [DruxtMenuMixin]
}
</script>

Example (default slot (template injection))

<DruxtMenu>
  <template #default="{ items }">
    <!-- Do whatever you want here -->
    <DruxtDebug :json="items" />
  </template>
</DruxtMenu>

.getMenuItems([entity], [position])

Recursively gets required menu items from the Vuex store.

Kind: instance method of DruxtMenu

ParamTypeDescription
[entity]objectCurrent menu item entity.
[position]numberCurrent position in the menu tree,

.error(err, [context])

Sets the component to render a DruxtDebug error message.

Kind: instance method of DruxtMenu

ParamTypeDescription
errobjectThe error object.
[context]objectError context; carries the wrapper component data where the failure knows it.

.getModuleComponents() ⇒ Components

Get list of module wrapper components.

Kind: instance method of DruxtMenu


.getModulePropsData(wrapperProps) ⇒ object

Get module propsData via modules druxt.propsData() callback.

Kind: instance method of DruxtMenu

ParamTypeDescription
wrapperPropsobjectProps registered by the Wrapper component.

Example

{
  $attrs: { entity: {}, fields: {}, langcode: 'en', schema: {} },
  props: { value: {} },
  propsData: { entity: {}, fields: {}, langcode: 'en', schema: {}, value: {} },
}

.getScopedSlots() ⇒ object

Gets a Druxt modules scoped slots, and if there's no default slots, provides a develop mode debug default or passes through to a default template.

Kind: instance method of DruxtMenu


.getWrapperData(component) ⇒ WrapperData

Get wrapper component data.

Kind: instance method of DruxtMenu

ParamTypeDescription
componentstringThe Wrapper component name.

.props

Kind: static property of DruxtMenu


.depth : number

The depth of the menu items to render.

Kind: static property of props
Default: 0
Example

<DruxtMenu :depth="1" />

.itemClass : string

Class(es) to apply to the menu items.

Kind: static property of props


.itemComponent : string

Component or element to render the menu items.

Kind: static property of props
Default: "li"


.maxDepth : number

The maximum depth of the menu tree data to load.

Kind: static property of props
Example

<DruxtMenu :max-depth="4" />

.minDepth : number

The minimum depth of the menu tree.

Kind: static property of props
Default: 0
Example

<DruxtMenu :min-depth="2" />

.name : string

The Drupal menu machine name (for example, main or footer) of the menu to load and render.

Kind: static property of props
Default: "main"
Example

<DruxtMenu name="main" />

.parentId : string

The menu parent ID to use as the root of the menu.

Kind: static property of props
Example

<DruxtMenu parent-id="views_view:views.recipes.page_1" />

.parentClass : string

Class(es) to apply to parent menu items.

Kind: static property of props


.parentComponent : string

Component or element to render parent menu items.

Kind: static property of props
Default: "li"


.parentWrapperClass : string

Class(es) to apply to a wrapper around parent menu items.

Kind: static property of props


.parentWrapperComponent : string

Component or element to render a wrapper around parent menu items.

Kind: static property of props
Default: "ul"


.langcode : string

The resource langcode.

Kind: static property of props
Example

@lang vue
<DruxtMenu langcode="en" />

.v-model : mixed

The Vue.js v-model binding for the module.

Setting a value provides the module data directly, so the Drupal JSON:API fetch is skipped.

Kind: static property of props
Default:
Example

@lang vue
<template>
  <DruxtMenu v-model="model" />
</template>

<script>
export default {
  data: () => ({ model: { foo: 'bar' } })
}
</script>

.wrapper : (boolean | object)

The wrapper component configuration.

Used to set the wrapper component, class, style and propsData.

Kind: static property of props
Default: () => undefined
Example

<DruxtMenu
  :wrapper="{
    component: 'BCard',
    class: 'article-card',
    propsData: { noBody: true }
  }"
/>

.computed

Kind: static property of DruxtMenu


.trail : Array.<string>

The active route trail.

Kind: static property of computed


.items : Array.<objects>

Deprecated in druxt-menu:0.11.0, removed from druxt-menu:2.0.0. Use the model property (v-model) instead.

The processed Menu items.

Kind: static property of computed
See: /modules/menu/deprecations


.watch

Kind: static property of DruxtMenu


.entities()

Updates menu when available Entities change.

Kind: static method of watch


.druxt

DruxtModule settings.

Kind: static property of DruxtMenu


.template

Druxt development template tool configuration.

Kind: static property of druxt


.componentOptions(context) ⇒ ComponentOptions

Provides the available component naming options for the Druxt Wrapper.

Kind: static method of druxt

ParamTypeDescription
contextobjectThe module component ViewModel.
context.namestringThe name of the menu to load and render.

.fetchData(settings)

Builds and executes the JSON:API query, loading the menu items into the druxtMenu Vuex store.

Kind: static method of druxt

ParamTypeDescription
settingsobjectThe module settings object, including the menu items query configuration.

.propsData(context) ⇒ PropsData

Provides propsData for the DruxtWrapper.

Kind: static method of druxt

ParamTypeDescription
contextobjectThe module component ViewModel.
context.modelArray.<object>The menu items model value.
context.parentIdstringThe menu parent ID to use as the root of the menu.

.settings(context, wrapperSettings) ⇒ object

Component settings.

Kind: static method of druxt
Returns: object - The merged module settings.

ParamTypeDescription
contextobjectThe module component ViewModel.
context.$druxtobjectThe Druxt Nuxt plugin instance.
context.depthnumberThe depth of the menu items to render.
context.maxDepthnumber | nullThe maximum depth of the menu tree data to load.
context.minDepthnumberThe minimum depth of the menu tree.
context.parentIdstringThe menu parent ID to use as the root of the menu.
wrapperSettingsobjectSettings provided by the Wrapper component.

.slots(h) ⇒ ScopedSlots

Provides the scoped slots object for the Module render function.

Adds a default slot that will render the menu tree using the DruxtMenuItem component.

Kind: static method of druxt
Returns: ScopedSlots - The Scoped slots object.

ParamTypeDescription
hfunctionThe Vue createElement function.

Example (DruxtMenuName.vue)

<template>
  <div>
    <slot />
  </div>
</template>

.methods

Kind: static property of DruxtMenu


.data(vm)

Kind: static method of DruxtMenu

ParamTypeDescription
vmobjectThe component ViewModel.
vm.value*The module component model value.

Properties

NameTypeDescription
componentComponentDataThe wrapper component and propsData to be rendered.
model*The module component model value.

.fetch()

Loads the Druxt module data and applies a wrapper component as required.

Important: If your component has an existing fetch method, you must manually invoke the DruxtModule.fetch() hook.

Kind: static method of DruxtMenu
Example (Manually invoking DruxtModule.fetch().)

import DruxtModule from 'druxt/components/DruxtModule.vue'
export default {
  name: 'DruxtCustomModule',
  extends: DruxtModule,
  async fetch() {
    await DruxtModule.fetch.call(this)
  },
  druxt: {
    componentOptions: () => ([['Default']]),
    propsData: ({ model }) => ({ value: model }),
  }
}

.lang(vm) ⇒ string

The current language code: the langcode prop if set, otherwise the route's langcode metadata.

Used by Druxt modules to fetch the correct resource translation.

Kind: static method of DruxtMenu
Returns: string - The current language code.

ParamTypeDescription
vmobjectThe component ViewModel.
vm.langcodestringThe langcode prop.
vm.$routeobjectThe current route.

ComponentOptions : Array.<array>

Provides the available naming options for the Wrapper component.

Kind: global typedef
Example

[
  'DruxtMenu[Name][Langcode]',
  'DruxtMenu[Name]',
  'DruxtMenu[Default][Langcode]',
  'DruxtMenu[Default]',
]

Example (Main menu (default))

[
  'DruxtMenuMainEn',
  'DruxtMenuMain',
  'DruxtMenuDefaultEn',
  'DruxtMenuDefault',
]

ModuleSettings : object

Provides settings for the Menu module, via the nuxt.config.js druxt.menu or the Wrapper component druxt object.

Kind: global typedef

ParamTypeDescription
fieldsArray.<string>An array of fields to filter all JSON:API Menu queries.
requiredOnlybooleanWhether to automatically filter to module defined minimum required fields.

Example

{
  fields: [],
  requiredOnly: true,
}

Example

<script>
export default {
  druxt: {
    query: {
      fields: ['description', 'options']
      requiredOnly: false,
    },
  }
}
</script>

PropsData : object

Provides propsData for use in the Wrapper component.

Kind: global typedef

ParamTypeDescription
itemsArray.<object>The Menu items structured data.
valueArray.<object>The Menu items structured data.

Example

{
  items: [
    {
      children: [],
      entity: {},
    },
  ],
  value: [
    {
      children: [],
      entity: {},
    },
  ],
}

ScopedSlots : object

Provides scoped slots for use in the Wrapper component.

Kind: global typedef

ParamTypeDescription
defaultfunctionAll menu items using the DruxtMenuItem component

Example (DruxtMenuName.vue)

<template>
  <div>
    <slot />
  </div>
</template>

Inherited type definitions

Inherited from DruxtModule: ComponentData, Components, WrapperData.