DruxtModule
DruxtModule
The DruxtModule component renders a Druxt module; import and extend the component to build your own module.
The component provides access to the Druxt Wrapper theming and fetch system via the druxt settings object.
See: Component resolution
Example
import DruxtModule from 'druxt/components/DruxtModule.vue'
export default {
name: 'DruxtCustomModule',
extends: DruxtModule,
druxt: {
async fetchConfig() {},
async fetchData(settings) {},
componentOptions: () => ([['Default']]),
propsData: ({ model }) => ({ value: model }),
slots(h) {
return {
default: (attrs) => h('div', { attrs }, [this.model])
}
}
}
}
- DruxtModule
- instance
- static
.error(err, [context])
Sets the component to render a DruxtDebug error message.
Kind: instance method of DruxtModule
| Param | Type | Description |
|---|---|---|
| err | object | The error object. |
| [context] | object | Error context; carries the wrapper component data where the failure knows it. |
.getModuleComponents() ⇒ Components
Get list of module wrapper components.
Kind: instance method of DruxtModule
.getModulePropsData(wrapperProps) ⇒ object
Get module propsData via modules druxt.propsData() callback.
Kind: instance method of DruxtModule
| Param | Type | Description |
|---|---|---|
| wrapperProps | object | Props 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 DruxtModule
.getWrapperData(component) ⇒ WrapperData
Get wrapper component data.
Kind: instance method of DruxtModule
| Param | Type | Description |
|---|---|---|
| component | string | The Wrapper component name. |
.props
Kind: static property of DruxtModule
.langcode : string
The resource langcode.
Kind: static property of props
Example
<DruxtModule langcode="en" />
.value : *
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
Model:
Example
<template>
<DruxtModule 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
Example
<DruxtModule
:wrapper="{
component: 'BCard',
class: 'article-card',
propsData: { noBody: true }
}"
/>
.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>
<DruxtModule v-model="model" />
</template>
<script>
export default {
data: () => ({ model: { foo: 'bar' } })
}
</script>
.methods
Kind: static property of DruxtModule
.data(vm)
Kind: static method of DruxtModule
| Param | Type | Description |
|---|---|---|
| vm | object | The component ViewModel. |
| vm.value | * | The module component model value. |
Properties
| Name | Type | Description |
|---|---|---|
| component | ComponentData | The 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 DruxtModule
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 }),
}
}
Components : Array.<object>
The list of candidate Wrapper components, with naming parts and global registration state.
Kind: global typedef
See: Component resolution
Properties
| Name | Type | Description |
|---|---|---|
| global | boolean | Component global registration state. |
| name | string | The component name. |
| parts | Array.<string> | The component naming parts. |
Example
[{
global: true,
name: 'DruxtEntityNodeArticleDefault',
parts: ['NodeArticle', 'Default'],
}]
ComponentData : object
The Wrapper component and propsData to be rendered.
Kind: global typedef
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| $attrs | object | propsData not registered by the Wrapper component. | |
| is | string | "DruxtWrapper" | The Wrapper component name. |
| options | Array.<string> | The Wrapper component options. | |
| props | object | propsData registered by the Wrapper component. | |
| propsData | object | The component propsData object. | |
| settings | object | Druxt settings object provided by the Wrapper component. |
Example
{
$attrs: { entity: {}, fields: {}, schema: {} },
is: 'DruxtEntityNodeArticleDefault',
options: [
'DruxtEntityNodeArticleDefault',
'DruxtEntityDefault',
],
props: { value: {} },
propsData: {
entity: {},
fields: {},
schema: {},
value: {},
},
settings: { query: {} },
}
WrapperData : object
Druxt settings and registered props retrieved from the Wrapper component.
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| druxt | object | Druxt settings object for use by Druxt module. |
| props | object | Registered props oject. |
Example
{
druxt: { query: { fields: ['path', 'title'] } },
props: {
value: {
type: Object,
default: () => ({}),
}
}
}