DruxtEntity
Modules
- DruxtEntity
The DruxtEntity component renders a Drupal Content Entity by JSON:API resource type, UUID, view mode and schema type.
Fields are rendered as DruxtField components, based on the Drupal display mode configuration.
Typedefs
- ComponentOptions :
Array.<array> Provides the available naming options for the Wrapper component.
- ModuleSettings :
object Provides settings for the Entity module, via the
nuxt.config.jsdruxt.entity, the Wrapper componentdruxtobject or the DruxtEntity componentsettingsproperty.- PropsData :
object Provides property data 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.
DruxtEntity
The DruxtEntity component renders a Drupal Content Entity by JSON:API resource type, UUID, view mode and schema type.
Fields are rendered as DruxtField components, based on the Drupal display mode configuration.
Example
<DruxtEntity
type="node--article"
:uuid="uuid"
mode="teaser"
/>
Example (DruxtEntity Wrapper component boilerplate)
<template>
<DruxtDebug :json="entity" />
</template>
<script>
import { DruxtEntityMixin } from 'druxt-entity'
export default {
mixins: [DruxtEntityMixin]
}
Example (DruxtEntity with template injection)
<DruxtEntity type="" uuid="">
<template #default="{ entity }">
<!-- Do whatever you want here -->
<DruxtDebug :json="entity" />
</template>
</DruxtEntity>
- DruxtEntity
- instance
- .getQuery(settings) ⇒
boolean|object - .isEmpty(value) ⇒
boolean
- .getQuery(settings) ⇒
- static
- instance
- static
- instance
.getQuery(settings) ⇒ boolean | object
Builds the query for the JSON:API request.
Kind: instance method of DruxtEntity
| Param | Type | Description |
|---|---|---|
| settings | ModuleSettings | The merged module and component settings object. |
.isEmpty(value) ⇒ boolean
Checks if an Entity field is empty.
Kind: instance method of DruxtEntity
| Param | Type | Description |
|---|---|---|
| value | * | Field value. |
.props
Kind: static property of DruxtEntity
.mode : string
Drupal display mode.
Kind: static property of props
Default: "default"
.settings : ModuleSettings
Module settings object.
Kind: static property of props
Default: {}
.schemaType : 'view' | 'form'
Drupal display schema type, 'view' or 'form'.
Kind: static property of props
.type : string
JSON:API resource type.
Kind: static property of props
.uuid : string
Entity UUID.
Kind: static property of props
.langcode
The resource langcode.
Kind: static property of props
Example
<DruxtEntity 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
<DruxtEntity 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
<DruxtEntity
:wrapper="{
component: 'BCard',
class: 'article-card',
propsData: { noBody: true }
}"
/>
.entity : object
The Drupal Entity JSON:API resource data.
Kind: static property of props
.fields : object
Drupal Entity Fields data.
Kind: static property of props
.schema : object
DruxtJS Schema object.
Kind: static property of props
.computed
Kind: static property of DruxtEntity
- .computed
- .entity ⇒
object - .fields ⇒
object - .classes() :
Array.<string>
- .entity ⇒
.entity ⇒ object
The Entity object.
Kind: static property of computed
Returns: object - .
| Param | Type | Description |
|---|---|---|
| vm | object | The component ViewModel. |
| vm.model | object | The model object. |
.fields ⇒ object
Entity fields based on Display mode.
Kind: static property of computed
| Param | Type | Description |
|---|---|---|
| vm | object | The component ViewModel. |
| vm.errors | Array.<object> | Form submission response errors, if any. |
| vm.isEmpty | function | Checks if an Entity field is empty. |
| vm.lang | string | The current language code. |
| vm.model | object | The model object. |
| vm.schema | object | The DruxtSchema object. |
| vm.schemaType | 'view' | 'form' | Drupal display schema type, 'view' or 'form'. |
.classes() : Array.<string>
Array of CSS classes.
Kind: static method of computed
.druxt
DruxtModule settings
Kind: static property of DruxtEntity
.template
Druxt development template tool configuration.
Kind: static property of druxt
.componentOptions(context) ⇒ ComponentOptions
Provides the available component naming options for the Druxt Wrapper.
Kind: static method of druxt
| Param | Type | Description |
|---|---|---|
| context | object | The module component ViewModel. |
| context.mode | string | The Drupal display mode. |
| context.schema | object | The DruxtSchema object. |
| context.schemaType | 'view' | 'form' | Drupal display schema type, 'view' or 'form'. |
| context.type | string | The JSON:API resource type. |
.fetchConfig()
Fetches the Druxt schema object.
Kind: static method of druxt
.fetchData(settings)
Fetches the content entity JSON:API resource.
Kind: static method of druxt
| Param | Type | Description |
|---|---|---|
| settings | object | The module settings object, including the resource query configuration. |
.propsData(context) ⇒ PropsData
Provides propsData for the DruxtWrapper.
Kind: static method of druxt
| Param | Type | Description |
|---|---|---|
| context | object | The module component ViewModel. |
| context.fields | object | Entity fields based on the display mode. |
| context.model | object | The model object. |
| context.schema | object | The DruxtSchema object. |
.settings(context, wrapperSettings) ⇒ object
Component settings.
Kind: static method of druxt
Returns: object - The merged module settings.
| Param | Type | Description |
|---|---|---|
| context | object | The module component ViewModel. |
| wrapperSettings | object | Settings provided by the Wrapper component. |
.slots(h) ⇒ ScopedSlots
Provides the scoped slots object for the Module render function.
A scoped slot is provided for each field being rendered, as per the current display mode.
Additionally, the default slot will render all fields as per the
Kind: static method of druxt
Returns: ScopedSlots - The Scoped slots object.
| Param | Type | Description |
|---|---|---|
| h | function | The Vue createElement function. |
Example (DruxtEntityResourceType.vue)
<template>
<div>
<slot name="content" />
<slot :name="field_name" />
</div>
</template>
.data(vm)
Kind: static method of DruxtEntity
| Param | Type | Description |
|---|---|---|
| vm | object | The component ViewModel. |
| vm.type | string | The JSON:API resource type. |
| vm.value | object | The module component model value. |
Properties
| Name | Type | Description |
|---|---|---|
| model | object | The model object. |
| schema | object | The DruxtSchema object. |
.error(err, [context])
Sets the component to render a DruxtDebug error message.
Kind: instance method of DruxtEntity
| 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 DruxtEntity
.getModulePropsData(wrapperProps) ⇒ object
Get module propsData via modules druxt.propsData() callback.
Kind: instance method of DruxtEntity
| 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 DruxtEntity
.getWrapperData(component) ⇒ WrapperData
Get wrapper component data.
Kind: instance method of DruxtEntity
| Param | Type | Description |
|---|---|---|
| component | string | The Wrapper component name. |
.methods
Kind: static property of DruxtEntity
.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 DruxtEntity
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 DruxtEntity
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
Example
[
'DruxtEntity[ResourceType][DisplayMode][SchemaType][Langcode]',
'DruxtEntity[ResourceType][DisplayMode][SchemaType]',
'DruxtEntity[EntityType][DisplayMode][SchemaType][Langcode]',
'DruxtEntity[EntityType][DisplayMode][SchemaType]',
'DruxtEntity[ResourceType][DisplayMode][Langcode]',
'DruxtEntity[ResourceType][DisplayMode]',
'DruxtEntity[EntityType][DisplayMode][Langcode]',
'DruxtEntity[EntityType][DisplayMode]',
'DruxtEntity[ResourceType][Langcode]',
'DruxtEntity[ResourceType]',
'DruxtEntity[EntityType][Langcode]',
'DruxtEntity[EntityType]',
'DruxtEntity[DisplayMode][Langcode]',
'DruxtEntity[DisplayMode]',
]
Example (Article Node (default))
[
'DruxtEntityNodeArticleDefaultViewEn',
'DruxtEntityNodeArticleDefaultView',
'DruxtEntityNodeDefaultViewEn',
'DruxtEntityNodeDefaultView',
'DruxtEntityNodeArticleDefaultEn',
'DruxtEntityNodeArticleDefault',
'DruxtEntityNodeDefaultEn',
'DruxtEntityNodeDefault',
'DruxtEntityNodeArticleEn',
'DruxtEntityNodeArticle',
'DruxtEntityNodeEn',
'DruxtEntityNode',
'DruxtEntityDefaultEn',
'DruxtEntityDefault',
]
ModuleSettings : object
Provides settings for the Entity module, via the nuxt.config.js druxt.entity,
the Wrapper component druxt object or the DruxtEntity component settings
property.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| query | object | Entity query settings: |
| query.bypassCache | boolean | function | Whether to pull the data from the Vuex store or from the JSON:API. |
| query.fields | Array.<string> | Array.<array> | An array or arrays of fields to filter from the JSON:API Resources. |
| query.include | Array.<string> | An array of relationships to include alongside the JSON:API Resource. |
| query.schema | boolean | Whether to automatically detect fields to filter, per the Display mode. |
Example (DruxtEntity Wrapper component)
<script>
export default {
druxt: {
query: {
bypassCache: ({ $store }) => $store.$auth.loggedIn,
fields: [['title'], ['user--user', ['display_name']]],
include: ['uid']
schema: true,
},
},
}
Example (DruxtEntity component with settings)
<template>
<DruxtEntity
type="node--article"
:uuid="uuid"
:settings="{
query: {
bypassCache: true,
fields: [['title'], ['user--user', ['display_name']]],
include: ['uid']
schema: true,
}
}"
/>
</template>
PropsData : object
Provides property data for use in the Wrapper component.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| entity | object | The Drupal Entity JSON:API resource data. |
| fields | object | Drupal Entity Fields data. |
| schema | object | DruxtJS Schema object. |
| value | object | The Entity value. |
Example
{
entity: {
attributes: {},
id: '43118086-cca5-4c62-b11e-f1d870050ebd',
links: {},
relationships: {},
type: 'node--article',
},
fields: {
body: {},
field_media_image: {},
field_tags: {},
},
schema: {
config: {},
fields: {},
groups: {},
id: 'node--article--default--view',
resourceType: 'node--article',
},
value: {},
}
ScopedSlots : object
Provides scoped slots for use in the Wrapper component.
Kind: global typedef
| Param | Type | Description |
|---|---|---|
| * | function | Slot per field. |
| default | function | All fields per Display mode. |
Example (DruxtEntityResourceType.vue)
<template>
<div>
<slot name="content" />
<slot :name="field_name" />
</div>
</template>
Components : Array.<object>
The list of candidate Wrapper components, with naming parts and global registration state.
Kind: global typedef
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: () => ({}),
}
}
}