https://github.com/realityloop/drupal_jsonapi_entities
Drupal JSON:API Entities
https://github.com/realityloop/drupal_jsonapi_entities
Last synced: 12 months ago
JSON representation
Drupal JSON:API Entities
- Host: GitHub
- URL: https://github.com/realityloop/drupal_jsonapi_entities
- Owner: Realityloop
- Created: 2019-07-25T05:35:49.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2025-03-28T09:41:17.000Z (12 months ago)
- Last Synced: 2025-03-28T10:42:28.443Z (12 months ago)
- Language: JavaScript
- Size: 3.32 MB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 32
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Drupal JSON:API Entities
[](https://circleci.com/gh/Realityloop/drupal_jsonapi_entities)
[](https://snyk.io//test/github/Realityloop/drupal_jsonapi_entities?targetFile=package.json)
[](https://codecov.io/gh/Realityloop/drupal_jsonapi_entities)
Build a Drupal Entity form/view field schema from your Drupal JSON:API entitiy
with ease.
## Installation
`$ npm install drupal_jsonapi_entities`
## Documentation
### new drupalJSONAPIEntities()
```js
import drupalJSONAPIEntities from 'drupal_jsonapi_entities'
const drupalEntities = new drupalJSONAPIEntities(url, options)
```
The constructor takes two arguments:
- `url`: The base URL of the Drupal instance.
- `options`: The API options.
#### Available API options (`options` argument)
- **auth**: An array for use authorizing the client with the Drupal instance.
Currently only supports OAuth2 password flow.
- **clientId**: The Oauth 2 Client ID.
- **clientSecret**: The Oauth 2 Client secret.
- **user**: The Drupal username.
- **pass**: The Drupal user passsword.
### getFormSchema()
```js
const formSchema = await drupalEntities.getFormSchema(entityType, bundle, mode)
```
The method takes three arguments:
- `entityType`: The Drupal entity type ID.
- `bundle`: The Drupal bundle ID for the entity type.
- `mode`: The form display mode. Default: `default`.
Returns a JSON object:
- **fields**: An array of field objects, sorted by weight.
- **cardinality**: Allowed number of values.
- **description**: Help text.
- **id**: Machine name.
- **property**: True if field is a property on the Drupal entity.
- **label**: Label.
- **required**: Required field.
- **settings**: Merged object of field settings.
- **type**: Field type machine name.
- **weight**: Form display field weight.
- **group**: (optional) Group.
- **groups**: An array of Drupal Field Group module group objects, sorted by weight.
- **children**: Array of fields in group.
- **format_settings**: Settings for the display of the group.
- **format_type**: Type of group for display.
- **id**: Machine name.
- **label**: Label.
- **weight**: Weight.
#### Drupal requirements
JSON:API resources:
- `entity_form_display--entity_form_display`
- `field_config--field_config`
- `field_storage_config--field_storage_config`
Permissions:
- `administer display modes`
- `administer ENTITY_TYPE fields`
### getViewSchema()
```js
const viewSchema = await drupalEntities.getViewSchema(entityType, bundle, mode)
```
The method takes three arguments:
- `entityType`: The Drupal entity type ID.
- `bundle`: The Drupal bundle ID for the entity type.
- `mode`: The view display mode. Default: `default`.
Returns a JSON object:
- **fields**: An array of field objects, sorted by weight.
- **description**: Help text.
- **id**: Machine name.
- **property**: True if field is a property on the Drupal entity.
- **label**: Label.
- **labelPosition**: Label position.
- **required**: Required field.
- **settings**: Merged object of field settings.
- **thirdPartySettings**: Settings of any third party modules.
- **type**: Field type machine name.
- **weight**: Form display field weight.
- **group**: (optional) Group.
- **groups**: An array of Drupal Field Group module group objects, sorted by weight.
- **children**: Array of fields in group.
- **format_settings**: Settings for the display of the group.
- **format_type**: Type of group for display.
- **id**: Machine name.
- **label**: Label.
- **weight**: Weight.
#### Drupal requirements
JSON:API resources:
- `entity_form_display--entity_form_display`
- `entity_view_display--entity_view_display`
- `field_config--field_config`
- `field_storage_config--field_storage_config`
Permissions:
- `administer display modes`
- `administer ENTITY_TYPE fields`
## Nuxt.js module
Drupal JSON:API Entities provides a Nuxt.js module for easily caching the
schema(s).
### Getting started with Nuxt.js
Add `drupal_jsonapi_entities/nuxt` to the modules section of your
`nuxt.config.js` file.
```js
module.exports = {
modules: [
// Drupal JSON:API entities.
[
'drupal_jsonapi_entities/nuxt',
{
baseUrl: process.env.API_URL,
auth: {
clientId: process.env.API_CONSUMER_CLIENT_ID,
clientSecret: process.env.API_CONSUMER_CLIENT_SECRET,
user: process.env.API_CONSUMER_USERNAME,
pass: process.env.API_CONSUMER_PASSWORD
}
}
],
]
}
```
Add a `drupalJSONAPIEntities` section to your `nuxt.config.js` file in the
following format for all required Entity types, Bundles, Schema types and
Modes:
```js
module.exports = {
drupalJSONAPIEntities: {
'entityType': { 'bundle': { 'type': [ 'mode' ] } }
}
}
```
Example:
```js
module.exports = {
drupalJSONAPIEntities: {
'node': {
'recipe': {
form: [ 'default' ],
view: [ 'default' ],
}
}
}
}
```
The module provides a plugin, which returns the Drupal JSON:API Entities
schema(s).
```js
this.$drupalJSONAPIEntities()
```