API Documentation
DruxtView
Modules
- DruxtView
The DruxtView component renders Drupal Views using configuration and results provided by the Drupal View and the JSON:API Views module.
The component renders slots for the View's headers, footers, entity results, exposed sorts and filters, and supports contextual filters.
Typedefs
- ComponentOptions :
Array.<array>
Provides the available component naming options for the Druxt Wrapper.
- ModuleSettings :
object
Provides settings for the View module, via the
nuxt.config.js
druxt.views
or the Wrapper componentdruxt
object.- PropsData :
object
Provides propsData for the DruxtWrapper.
- ScopedSlots :
object
Provides scoped slots for use in the Wrapper component.
DruxtView
The DruxtView component renders Drupal Views using configuration and results provided by the Drupal View and the JSON:API Views module.
The component renders slots for the View's headers, footers, entity results, exposed sorts and filters, and supports contextual filters.
Example
<DruxtView display-id="block_1" view-id="promoted_items" />
Example (View with contextual filter)
<DruxtView
:arguments="[entity.attributes.drupal_internal__nid]"
display-id="block_1"
view-id="articles_aside"
/>
Example (DruxtView Wrapper component boilerplate)
<template>
<DruxtDebug :json="results" />
</template>
<script>
import { DruxtViewsViewMixin } from 'druxt-views'
export default {
mixins: [DruxtViewsViewMixin]
}
Example (DruxtView with template injection)
<DruxtView>
<template #default="{ results }">
<!-- Do whatever you want here -->
<DruxtDebug :json="results" />
</template>
</DruxtView>
- DruxtView
- instance
- static
- .props
- .arguments :
array
- .displayId :
string
- .settings :
ModuleSettings
- .type :
string
- .uuid :
string
- .viewId :
string
- .langcode
- .v-model
- .wrapper
- .arguments :
- .computed
- .attachments_after :
Array.<string>
- .attachments_before :
Array.<string>
- .count :
integer
- .display :
object
- .filters :
Array.<object>
- .headers
- .mode :
string
- .pager :
object
- .results :
Array.<object>
- .showPager :
boolean
- .showSorts :
boolean
- .sorts :
Array.<object>
- .attachments_after :
- .druxt
- .data()
- .props
Query
.getQuery(settings) ⇒ Builds the query for the JSON:API request.
Kind: instance method of DruxtView
Param | Type | Description |
---|---|---|
settings | ModuleSettings | The merged module and component settings object. |
.onFiltersUpdate()
Filters update event handler.
Kind: instance method of DruxtView
.props
Vue.js Properties.
Kind: static property of DruxtView
- .props
- .arguments :
array
- .displayId :
string
- .settings :
ModuleSettings
- .type :
string
- .uuid :
string
- .viewId :
string
- .langcode
- .v-model
- .wrapper
- .arguments :
array
.arguments : Views contextual filters.
Kind: static property of props
Default: []
Example
<DruxtView :arguments="[1, 2, 3]" display-id="block_1" view-id="articles_aside" />
string
.displayId : The View Display ID.
Kind: static property of props
Default: "default"
Example
<DruxtView display-id="page_1" view-id="frontpage" />
ModuleSettings
.settings : Module settings object.
Kind: static property of props
Default: {}
string
.type : JSON:API Resource type.
Kind: static property of props
Default: "view--view"
string
.uuid : The View UUID.
Kind: static property of props
Example
<DruxtView uuid="f6c38097-d534-4bfb-87d9-09526fe44e9c" />
string
.viewId : The View ID.
Kind: static property of props
Example
<DruxtView view-id="frontpage" />
.langcode
The resource langcode.
Kind: static property of props
Example
<DruxtView 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
<DruxtView 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
<DruxtView
:wrapper="{
component: 'MyWrapper',
class: 'wrapper',
propsData: { foo: 'bar' }
}"
/>
.computed
Kind: static property of DruxtView
- .computed
- .attachments_after :
Array.<string>
- .attachments_before :
Array.<string>
- .count :
integer
- .display :
object
- .filters :
Array.<object>
- .headers
- .mode :
string
- .pager :
object
- .results :
Array.<object>
- .showPager :
boolean
- .showSorts :
boolean
- .sorts :
Array.<object>
- .attachments_after :
Array.<string>
.attachments_after : IDs of displays to be attached after the view.
Kind: static property of computed
Array.<string>
.attachments_before : IDs of displays to be attached before the view.
Kind: static property of computed
integer
.count : The total item count.
Kind: static property of computed
object
.display : The View Display object.
Kind: static property of computed
Array.<object>
.filters : Exposed filters.
Kind: static property of computed
.headers
The View Headers data.
Kind: static property of computed
string
.mode : The View mode for the results entities.
Kind: static property of computed
object
.pager : The displays pager settings.
Kind: static property of computed
Array.<object>
.results : The JSON:API Views results.
Kind: static property of computed
boolean
.showPager : Whether a pager should be shown.
Kind: static property of computed
boolean
.showSorts : Whether Exposed sorts are available and should be displayed.
Kind: static property of computed
Array.<object>
.sorts : Exposed sorts.
Kind: static property of computed
.druxt
DruxtModule settings
Kind: static property of DruxtView
.template
Druxt development template tool configuration.
Kind: static property of druxt
ComponentOptions
.componentOptions(context) ⇒ Provides the available component naming options for the Druxt Wrapper.
Kind: static method of druxt
Param | Type | Description |
---|---|---|
context | object | The module component ViewModel. |
.fetchConfig()
Fetch View configuration resource.
Kind: static method of druxt
.fetchData()
Fetch JSON:API Views results.
Kind: static method of druxt
PropsData
.propsData(context) ⇒ Provides propsData for the DruxtWrapper.
Kind: static method of druxt
Param | Type | Description |
---|---|---|
context | object | The module component ViewModel. |
.settings()
Component settings.
Kind: static method of druxt
ScopedSlots
.slots() ⇒ Provides the scoped slots object for the Module render function.
- header
- filters
- sorts
- attachments_before
- results
- pager
- attachments_after
- default (all of the above)
Kind: static method of druxt
Returns: ScopedSlots
- The Scoped slots object.
Example (DruxtViewViewId.vue)
<template>
<div>
<slot name="header" />
<slot name="results" />
<slot name="pager" />
</div>
</template>
.data()
Kind: static method of DruxtView
Properties
Name | Type | Description |
---|---|---|
model | object | The model object. |
resource | object | The JSON:API Views resource. |
view | object | The View JSON:API resource. |
Array.<array>
ComponentOptions : Provides the available component naming options for the Druxt Wrapper.
Kind: global typedef
Example
[
'DruxtView[ViewId][DisplayId][Langcode]',
'DruxtView[ViewId][DisplayId]',
'DruxtView[ViewId][Langcode]',
'DruxtView[ViewId]',
'DruxtView[UUID][DisplayId][Langcode]',
'DruxtView[UUID][DisplayId]',
'DruxtView[UUID][Langcode]',
'DruxtView[UUID]',
'DruxtView[DisplayId][Langcode]',
'DruxtView[DisplayId]',
]
Example (featured_articles (default))
[
'DruxtViewFeaturedArticlesDefaultEn',
'DruxtViewFeaturedArticlesDefault',
'DruxtViewFeaturedArticlesEn',
'DruxtViewFeaturedArticles',
'DruxtView16f5d68e5bae4d7aa61c6b2bc3b6d3b6DefaultEn',
'DruxtView16f5d68e5bae4d7aa61c6b2bc3b6d3b6Default',
'DruxtView16f5d68e5bae4d7aa61c6b2bc3b6d3b6En',
'DruxtView16f5d68e5bae4d7aa61c6b2bc3b6d3b6',
'DruxtViewDefaultEn',
'DruxtViewDefault',
]
object
ModuleSettings : Provides settings for the View module, via the nuxt.config.js
druxt.views
or the Wrapper component druxt
object.
Kind: global typedef
Param | Type | Description |
---|---|---|
query | object | View results query settings: |
query.bypassCache | boolean | function | Whether to pull the data from the Vuex store or from the JSON:API. |
query.bundleFilter | boolean | Whether to automatically detect Resource types to filter, based on the View bundle filter. |
query.fields | Array.<string> | An array of fields to filter from the JSON:API Views Resource types. |
query.resourceTypes | Array.<string> | An array of Resource types to be used by the Fields filter. |
Example (DruxtView Wrapper component)
<script>
export default {
druxt: {
query: {
bypassCache: ({ $store }) => $store.$auth.loggedIn,
bundleFilter: false,
fields: [],
resourceTypes: ['node--article'],
},
},
}
Example (DruxtView component with settings)
<template>
<DruxtView
display-id="block_1"
view-id="promoted_items
:settings="{
query: {
bypassCache: true,
bundleFilter: false,
fields: ['title']
resourceTypes: [],
}
}"
/>
</template>
object
PropsData : Provides propsData for the DruxtWrapper.
Kind: global typedef
Param | Type | Description |
---|---|---|
count | integer | The total item count. |
display | object | The View Display object. |
mode | string | The View mode for the results entities. |
pager | object | The displays pager settings. |
results | Array.<object> | The JSON:API Views results. |
view | object | The View JSON:API resource. |
Example
{
count: 8,
display: {},
mode: 'card',
pager: {
options: {},
type: 'mini',
},
results: [],
view: {},
}
object
ScopedSlots : Provides scoped slots for use in the Wrapper component.
Kind: global typedef
Param | Type | Description |
---|---|---|
header | function | The View header. |
filters | function | The Exposed filters. |
sorts | function | The Exposed sorts. |
attachments_before | function | Views attached before current display. |
results | function | The results as DruxtEntity components, or empty results output. |
pager | function | The View pager. |
attachments_after | function | Views attached after current display. |
default | function | All of the above. |
Example
{
header: () => {},
filters: () => {},
sorts: () => {},
attachments_before: () => {},
results: () => {},
pager: () => {},
attachments_after: () => {},
default: () => {},
}
Example (DruxtViewViewId.vue)
<template>
<div>
<slot name="header" />
<slot name="results" />
<slot name="pager" />
</div>
</template>