DruxtBlockRegion
DruxtBlockRegion
The DruxtBlockRegion component renders visible blocks based on region and theme.
All blocks, including those not visible, are provided as slots for the Druxt Wrapper component.
See
Example
<DruxtBlockRegion name="header" theme="umami" />
Example (DruxtBlockRegion Wrapper component boilerplate)
<template>
<DruxtDebug :json="blocks" />
</template>
<script>
import { DruxtBlocksRegionMixin } from 'druxt-blocks'
export default {
mixins: [DruxtBlocksRegionMixin]
}
</script>
Example (DruxtBlockRegion default slot (template injection))
<DruxtBlockRegion name="header" theme="umami">
<template #default="{ blocks }">
<!-- Do whatever you want here -->
<DruxtDebug :json="blocks" />
</template>
</DruxtBlockRegion>
- DruxtBlockRegion
- instance
- .isVisible(block) ⇒
boolean - .error(err, [context])
- .getModuleComponents() ⇒
Components - .getModulePropsData(wrapperProps) ⇒
object - .getScopedSlots() ⇒
object - .getWrapperData(component) ⇒
WrapperData
- .isVisible(block) ⇒
- static
- instance
.isVisible(block) ⇒ boolean
Checks if a given block should be visible.
Uses Request Path visibility details if available with the DruxtRouter.
Kind: instance method of DruxtBlockRegion
Returns: boolean - true if the block should be rendered on the current route.
| Param | Type | Description |
|---|---|---|
| block | object | The Block entity object. |
.error(err, [context])
Sets the component to render a DruxtDebug error message.
Kind: instance method of DruxtBlockRegion
| 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 DruxtBlockRegion
.getModulePropsData(wrapperProps) ⇒ object
Get module propsData via modules druxt.propsData() callback.
Kind: instance method of DruxtBlockRegion
| 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 DruxtBlockRegion
.getWrapperData(component) ⇒ WrapperData
Get wrapper component data.
Kind: instance method of DruxtBlockRegion
| Param | Type | Description |
|---|---|---|
| component | string | The Wrapper component name. |
.props
Kind: static property of DruxtBlockRegion
.name : string
A region machine name from the Drupal theme's block layout (/admin/structure/block).
Kind: static property of props
Default: "content"
Example
<DruxtBlockRegion name="header" :theme="theme" />
.theme : string
The machine name of the Drupal theme that provides the block layout.
Kind: static property of props
Required:
Example
<DruxtBlockRegion theme="umami" />
.langcode : string
The resource langcode.
Kind: static property of props
Example
@lang vue
<DruxtBlockRegion 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>
<DruxtBlockRegion 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
<DruxtBlockRegion
:wrapper="{
component: 'BCard',
class: 'article-card',
propsData: { noBody: true }
}"
/>
.computed
Kind: static property of DruxtBlockRegion
.route : object
The current Route from the DruxtRouter vuex store.
Kind: static property of computed
.druxt
DruxtModule configuration.
Kind: static property of DruxtBlockRegion
.template
Druxt development template tool configuration.
Kind: static property of druxt
.componentOptions(context) ⇒ ComponentOptions
Provides the available component naming options for the DruxtWrapper.
Kind: static method of druxt
| Param | Type | Description |
|---|---|---|
| context | object | The module component ViewModel. |
| context.name | string | The region machine name. |
| context.theme | string | The Drupal theme machine name. |
.fetchConfig()
Fetches all blocks by region and theme.
Kind: static method of druxt
.propsData(context) ⇒ PropsData
Provides propsData for the DruxtWrapper.
Kind: static method of druxt
| Param | Type | Description |
|---|---|---|
| context | object | The module component ViewModel. |
| context.blocks | Array.<object> | The Block JSON:API resources for the region. |
| context.name | string | The region machine name. |
| context.theme | string | The Drupal theme machine name. |
.slots(h) ⇒ ScopedSlots
Provides the scoped slots object for the Module render function.
A scoped slot is provided for each block in the region, regardless of visibility.
The default slot will render all blocks, filtered by route visibility.
Kind: static method of druxt
Returns: ScopedSlots - The Scoped slots object.
| Param | Type | Description |
|---|---|---|
| h | function | The Vue createElement function. |
Example (DruxtBlockRegionName.vue)
<template>
<div v-if="default">
<slot />
</div>
<div v-else>
<slot name="umami_branding" />
</div>
</template>
.data()
Provides the fetched Block resources for the region.
Kind: static method of DruxtBlockRegion
Properties
| Name | Type | Description |
|---|---|---|
| blocks | Array.<object> | The Block JSON:API resources. |
.methods
Kind: static property of DruxtBlockRegion
.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 DruxtBlockRegion
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 DruxtBlockRegion
Returns: string - The current language code.
| Param | Type | Description |
|---|---|---|
| vm | object | The component ViewModel. |
| vm.langcode | string | The langcode prop. |
| vm.$route | object | The current route. |
ComponentOptions : Array.<array>
Provides the available naming options for the Wrapper component.
Kind: global typedef
See: Component resolution
Example
[
'DruxtBlockRegion[Name][Theme][Langcode]',
'DruxtBlockRegion[Name][Theme]',
'DruxtBlockRegion[Name][Langcode]',
'DruxtBlockRegion[Name]',
'DruxtBlockRegion[Default][Langcode]',
'DruxtBlockRegion[Default]',
]
Example (Banner top - Umami)
[
'DruxtBlockRegionBannerTopUmamiEn',
'DruxtBlockRegionBannerTopUmami',
'DruxtBlockRegionBannerTopEn',
'DruxtBlockRegionBannerTop',
'DruxtBlockRegionDefaultEn',
'DruxtBlockRegionDefault',
]
PropsData : object
Provides propsData for use in the Wrapper component.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| blocks | Array.<object> | The Block JSON:API resources. |
| name | string | The region machine name. |
| theme | string | The Drupal theme machine name. |
Example
{
blocks: [{
attributes: {},
id: '59104acd-88e1-43c3-bd5f-35800f206394',
links: {},
relationships: {},
type: 'block--block',
}],
name: 'banner_top,
theme: 'umami',
}
ScopedSlots : object
Provides scoped slots for use in the Wrapper component.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| [drupal_internal__id] | function | Slot per block. |
| default | function | All blocks, filtered by route visibility. |
Example (DruxtBlockRegionName.vue)
<template>
<div v-if="default">
<slot />
</div>
<div v-else>
<slot name="umami_branding" />
</div>
</template>
Inherited type definitions
Inherited from DruxtModule: ComponentData, Components, WrapperData.