Skip to content

Render Drupal blocks and block regions in Nuxt with the druxt-blocks components, themed through the Druxt component suggestion system.

DruxtBlockRegion

View source on GitHub

Modules

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.

Typedefs

ComponentOptions : Array.<array>

Provides the available naming options for the Wrapper component.

PropsData : object

Provides propsData for use in the Wrapper component.

ScopedSlots : object

Provides scoped slots for use in the Wrapper component.

Components : Array.<object>

The list of candidate Wrapper components, with naming parts and global registration state.

ComponentData : object

The Wrapper component and propsData to be rendered.

WrapperData : object

Druxt settings and registered props retrieved from the Wrapper component.

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.

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]
}

Example (DruxtBlockRegion with template injection)

<DruxtBlock id="umami_branding">
  <template #default="{ block }">
    <!-- Do whatever you want here -->
    <DruxtDebug :json="block" />
  </template>
</DruxtBlock>

.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

ParamTypeDescription
blockobjectThe Block entity object.

.props

Kind: static property of DruxtBlockRegion


.name : string

The Block regions machine name.

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

<DruxtBlockRegion name="header" :theme="theme" />

.theme : string

A Drupal theme machine name.

Kind: static property of props
Required:
Example

<DruxtBlockRegion theme="umami" />

.langcode

The resource langcode.

Kind: static property of props
Example

<DruxtBlockRegion langcode="en" />

.v-model

The module component model value.

Used to bypass the Drupal JSON:API fetch, setting the module data directly.

Kind: static property of props
Example

<DruxtBlockRegion v-model="{ foo: bar }" />

.wrapper

The wrapper component configuration.

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

Kind: static property of props
Example

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

.blocks : Array.<objects>

The Block JSON:API resources.

Kind: static property of props
Required:


.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

ParamTypeDescription
contextobjectThe module component ViewModel.
context.namestringThe Block regions machine name.
context.themestringA 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

ParamTypeDescription
contextobjectThe module component ViewModel.
context.blocksArray.<object>The Block JSON:API resources for the region.
context.namestringThe Block regions machine name.
context.themestringA 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.

ParamTypeDescription
hfunctionThe Vue createElement function.

Example (DruxtBlockRegionName.vue)

<template>
  <div v-if="default">
    <slot />
  </div>

  <div v-else>
    <slot name="umami_branding" />
  </div>
</template>

.data()

Kind: static method of DruxtBlockRegion
Properties

NameTypeDescription
blocksArray.<objects>The Block JSON:API resources.

.error(err, [context])

Sets the component to render a DruxtDebug error message.

Kind: instance method of DruxtBlockRegion

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 DruxtBlockRegion


.getModulePropsData(wrapperProps) ⇒ object

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

Kind: instance method of DruxtBlockRegion

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 DruxtBlockRegion


.getWrapperData(component) ⇒ WrapperData

Get wrapper component data.

Kind: instance method of DruxtBlockRegion

ParamTypeDescription
componentstringThe Wrapper component name.

.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.

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

[
  '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

ParamTypeDescription
blocksArray.<object>The Block JSON:API resources.
namestringThe Block regions machine name.
themestringA 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

ParamTypeDescription
[drupal_internal__id]functionSlot per block.
defaultfunctionAll blocks, filtered by route visibility.

Example (DruxtBlockRegionName.vue)

<template>
  <div v-if="default">
    <slot />
  </div>

  <div v-else>
    <slot name="umami_branding" />
  </div>
</template>

Components : Array.<object>

The list of candidate Wrapper components, with naming parts and global registration state.

Kind: global typedef
Properties

NameTypeDescription
globalbooleanComponent global registration state.
namestringThe component name.
partsArray.<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

NameTypeDefaultDescription
$attrsobjectpropsData not registered by the Wrapper component.
isstring"DruxtWrapper"The Wrapper component name.
optionsArray.<string>The Wrapper component options.
propsobjectpropsData registered by the Wrapper component.
propsDataobjectThe component propsData object.
settingsobjectDruxt 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

NameTypeDescription
druxtobjectDruxt settings object for use by Druxt module.
propsobjectRegistered props oject.

Example

{
  druxt: { query: { fields: ['path', 'title'] } },
  props: {
    value: {
      type: Object,
      default: () => ({}),
    }
  }
}