Skip to content

Drupal Content Entity schema generator for Druxt with support for View and Form displays.

Schema (druxt-schema)

View source on GitHub

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


new Schema(config, context)

Schema constructor.

ParamTypeDescription
configSchemaConfigurationThe Schema configuration object.
contextobjectAdditional Schema generation context.
context.druxtSchemaDruxtSchemaA DruxtSchema instance, used to fetch the display and field configuration.
[context.data]objectPreloaded 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.

ParamTypeDescription
resourcestringThe JSON:API resource type.
querystring | objectA 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