Schema (druxt-schema)
Schema
The Schema generator utility.
Generates a Druxt Schema object for a single Drupal Entity display mode, using Entity Form and View Display configuration data from the Drupal JSON:API.
Used by the DruxtSchema class to build the schema files consumed by the DruxtEntity module; it is not typically used directly.
Kind: global class
See: Schema module guide
- Schema
- new Schema(config, context)
- .generate() ⇒
object|boolean - .getResources(resource, query) ⇒
object - .form() ⇒
object|boolean - .view() ⇒
object|boolean
new Schema(config, context)
Schema constructor.
| Param | Type | Description |
|---|---|---|
| config | SchemaConfiguration | The Schema configuration object. |
| context | object | Additional Schema generation context. |
| context.druxtSchema | DruxtSchema | A DruxtSchema instance, used to fetch the display and field configuration. |
| [context.data] | object | Preloaded JSON:API resource data. |
Example
const schema = new Schema({ entityType: 'node', bundle: 'page' }, { druxtSchema })
const data = await schema.generate()
.generate() ⇒ object | boolean
Generates the schema, as per the configured schema type ('view' or 'form').
Kind: instance method of Schema
Returns: object | boolean - The generated schema, or false if the display configuration is unavailable.
Example
const data = await schema.generate()
.getResources(resource, query) ⇒ object
Gets a collection of JSON:API resources, using preloaded data where available.
Kind: instance method of Schema
Returns: object - The JSON:API collection data.
| Param | Type | Description |
|---|---|---|
| resource | string | The JSON:API resource type. |
| query | string | object | A correctly formatted JSON:API query string or object. |
.form() ⇒ object | boolean
Generates the Form schema fields, using the Entity Form Display, Field Config and Field Storage Config resources.
Kind: instance method of Schema
Returns: object | boolean - The generated schema, or false if the display configuration is unavailable.
.view() ⇒ object | boolean
Generates the View schema fields, using the Entity View Display and Field Config resources.
Kind: instance method of Schema
Returns: object | boolean - The generated schema, or false if the display configuration is unavailable.
SchemaConfiguration : object
Druxt Schema configuration object.
Kind: global typedef
See: SchemaConfiguration