DruxtEntityForm
DruxtEntityForm ⇐ DruxtEntity
The DruxtEntityForm component renders a Drupal Content Entity edit form by JSON:API resource type, UUID, view mode and schema type.
Fields are rendered as DruxtField components, based on the Drupal display mode configuration.
Extends: DruxtEntity
See
Example
<DruxtEntityForm
:type="resourceType"
:uuid="uuid"
:mode="displayMode"
v-on:error="onError()"
v-on:reset="onReset()"
v-on:submit="onSubmit()"
/>
Example (DruxtEntityForm Wrapper component boilerplate)
<template>
<DruxtDebug :json="entity" />
</template>
<script>
import { DruxtEntityMixin } from 'druxt-entity'
export default {
mixins: [DruxtEntityMixin]
}
</script>
Example (DruxtEntityForm default slot (template injection))
<DruxtEntityForm type="">
<template #default="{ entity }">
<!-- Do whatever you want here -->
<DruxtDebug :json="entity" />
</template>
</DruxtEntity>
- DruxtEntityForm ⇐
DruxtEntity- instance
- .onReset()
- .onSubmit()
- .getQuery(settings) ⇒
boolean|object - .isEmpty(value) ⇒
boolean
- static
- .extends
- .props
- .schemaType :
'view'|'form' - .langcode :
string - .v-model :
mixed - .wrapper :
(boolean|object) - .mode :
string - .settings :
ModuleSettings - .type :
string - .uuid :
(boolean|string)
- .schemaType :
- .computed
- .errors ⇒
Array.<object>
- .errors ⇒
- .data()
- .druxt
- .entity(vm) ⇒
object - .fields(vm) ⇒
object - .componentOptions(context) ⇒
ComponentOptions - .fetchConfig()
- .fetchData(settings)
- .propsData(context) ⇒
PropsData - .settings(context, wrapperSettings) ⇒
object
- instance
.onReset()
Reset event handler:
- Sets
modelback toentityvalue. - Unsets
responsedata. - Emits
reset.
Kind: instance method of DruxtEntityForm
.onSubmit()
Submit event handler:
- Sends data to backend via POST or PATCH.
- Catches errors.
- Emits
submitorerrorevent.
Kind: instance method of DruxtEntityForm
.getQuery(settings) ⇒ boolean | object
Builds the query for the JSON:API request.
Kind: instance method of DruxtEntityForm
Returns: boolean | object - The DrupalJsonApiParams query object.
| 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 DruxtEntityForm
Returns: boolean - true if the field value is empty.
| Param | Type | Description |
|---|---|---|
| value | * | Field value. |
.extends
Kind: static property of DruxtEntityForm
See: DruxtEntity
.props
Vue.js Properties.
Kind: static property of DruxtEntityForm
- .props
- .schemaType :
'view'|'form' - .langcode :
string - .v-model :
mixed - .wrapper :
(boolean|object) - .mode :
string - .settings :
ModuleSettings - .type :
string - .uuid :
(boolean|string)
- .schemaType :
.schemaType : 'view' | 'form'
Drupal display schema type, 'view' or 'form'.
Kind: static property of props
Default: form
.langcode : string
The resource langcode.
Kind: static property of props
Example
@lang vue
<DruxtEntityForm 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>
<DruxtEntityForm 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
<DruxtEntityForm
:wrapper="{
component: 'BCard',
class: 'article-card',
propsData: { noBody: true }
}"
/>
.mode : string
Drupal display mode.
Kind: static property of props
Default: "default"
.settings : ModuleSettings
Module settings object.
Kind: static property of props
Default: [object Object]
.type : string
JSON:API resource type.
Kind: static property of props
.uuid : (boolean | string)
Entity UUID.
Kind: static property of props
Default: false
.computed
Vue.js Computed properties.
Kind: static property of DruxtEntityForm
.errors ⇒ Array.<object>
An array of errors if present in the form submission response data.
Kind: static property of computed
Returns: Array.<object> - The JSON:API errors from the form submission response, or undefined.
| Param | Type | Description |
|---|---|---|
| vm | object | The component ViewModel. |
| vm.response | object | The form submission response data. |
.data()
Vue.js Data object.
Kind: static method of DruxtEntityForm
Properties
| Name | Type | Description |
|---|---|---|
| response | object | The form submission response data. |
| submitting | boolean | Whether the form is currently being submitted. |
.druxt
DruxtModule settings
Kind: static property of DruxtEntityForm
.slots(h) ⇒ object
Adds a buttons slot to the DruxtEntity scope slots.
Kind: static method of druxt
Returns: object - The DruxtEntity scoped slots, with an added buttons slot and a default slot that appends the form buttons after the fields.
| Param | Type | Description |
|---|---|---|
| h | function | The Vue createElement function. |
.template
Druxt development template tool configuration.
Kind: static property of druxt
.entity(vm) ⇒ object
The Entity object.
Kind: static method of DruxtEntityForm
Returns: object - A copy of the entity model, containing the JSON:API attributes, relationships and included resource data.
| Param | Type | Description |
|---|---|---|
| vm | object | The component ViewModel. |
| vm.model | object | The model object. |
.fields(vm) ⇒ object
Entity fields based on Display mode.
Kind: static method of DruxtEntityForm
Returns: object - Field objects keyed by field ID, each containing the field's schema, value, errors and relationship status.
| 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'. |
.componentOptions(context) ⇒ ComponentOptions
Provides the available component naming options for the Druxt Wrapper.
Kind: static method of DruxtEntityForm
| 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 DruxtEntityForm
.fetchData(settings)
Fetches the content entity JSON:API resource.
Kind: static method of DruxtEntityForm
| 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 DruxtEntityForm
| 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 DruxtEntityForm
Returns: object - The merged module settings.
| Param | Type | Description |
|---|---|---|
| context | object | The module component ViewModel. |
| wrapperSettings | object | Settings provided by the Wrapper component. |
ComponentOptions : Array.<array>
Provides the available naming options for the Wrapper component.
Kind: global typedef
See: Component resolution
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,
},
},
}
</script>
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>