Skip to content

Drupal Views components for Druxt with support for filters, pagination and sorting.

DruxtViewsStore

View source on GitHub

DruxtViewsStore

Vuex module, registered under the druxt/views namespace. The druxt/views Vuex module.

Provides a Vuex state object, mutations and actions for interacting with JSON:API Views.

See: The DruxtStore


getResults(context, payload) ⇒ object | boolean

Get View results.

  • Executes query against Drupal JSON:API.
  • Caches result in the Vuex store.
  • Returns cached result from Vuex store when available.
    Vuex Action => Mutates state propertyresults

Kind: action method of druxt/views
Returns: object | boolean - The JSON:API Views results resource, or false where the request failed with nothing cached.

ParamTypeDescription
contextobjectThe Vuex action context.
context.commitfunctionCommits mutations to the store.
context.stateobjectThe Vuex module state.
payloadgetResultsContextThe action parameters.

Example

const { data, meta, links } = await this.$store.dispatch('druxt/views/getResults', {
  viewId,
  displayId,
  query,
  bypassCache: false
})

state : object

Vuex State object.

Read only: true
Properties

NameTypeDescription
resultsobjectJSON:API Views results store.

addResults

Adds JSON:API Views results to the Vuex state object.

Kind: mutation method of druxt/views

ParamTypeDescription
stateobjectThe Vuex state object.
payloadaddResultsPayloadThe mutation payload.

Example

this.$store.commit('druxt/views/addResults', { results, viewId, displayId, prefix, hash })

flushResults

Removes JSON:API Views results from the Vuex state object.

Kind: mutation method of druxt/views

ParamTypeDescription
stateobjectThe Vuex state object.
payloadflushResultsPayloadThe mutation payload.

Example

// Flush all results.
this.$store.commit('druxt/views/flushResults', {})

// Flush target results.
this.$store.commit('druxt/views/flushResults', { viewId, displayId, prefix, hash })

addResultsPayload : object

Parameters for the addResults mutation.

Kind: global typedef

ParamTypeDescription
resultsarrayThe Drupal JSON:API Views results.
viewIdstringThe Drupal View ID.
displayIdstringThe Drupal View Display ID.
[prefix]string(Optional) The JSON:API endpoint prefix or langcode.
hashstringA unique hash based of the query string.

Example

{
  results: [{ ... }],
  viewId: 'promoted_items',
  displayId: 'block_1',
  prefix: 'en',
  hash: '_default'
}

flushResultsPayload : object

Parameters for the flushResults mutation.

Kind: global typedef

ParamTypeDescription
[viewId]stringThe Drupal View ID.
[displayId]stringThe Drupal View Display ID.
[prefix]string(Optional) The JSON:API endpoint prefix or langcode.
[hash]stringA unique hash based of the query string.

Example

{
  viewId: 'promoted_items',
  displayId: 'block_1',
  prefix: 'en',
  hash: '_default'
}

getResultsContext : object

Parameters for the getResults action.

Kind: global typedef

ParamTypeDescription
viewIdstringThe Drupal View ID.
displayIdstringThe Drupal View Display ID.
[query]string | object(Optional) JSON:API Views query string.
[prefix]string(Optional) The JSON:API endpoint prefix or langcode.
[bypassCache]boolean(Optional) Bypass the Vuex cached results.

Example

{
  viewId: 'promoted_items',
  displayId: 'block_1',
  query: new DrupalJsonApiParams(),
  prefix: 'en',
  bypassCache: true
}