The Drupal-connector is a helper package for calling Drupal Back-end, and more features.
npm install --save drupal-connector
import React, { Component } from 'react';
import Drupal from 'drupal-connector';
const ConnectionDrupal = new Drupal({
baseUrl: 'http://drupal.dd:8083/',
});
const fetchData = async() => {
const node = await ConnectionDrupal.callAPI('node').get('94e611da-d83b-4d4d-aa4a-b69d00c00112', { bundle: "article" });
const optionNode = await ConnectionDrupal.callAPI('node').getAll(
{
bundle: "article",
filter: [
{ name_1: { value: "value 1", operator: "CONTAINS", path: "body.value", memberOf:"g_1" } },
{ name_2: { value: "value 2", operator: "CONTAINS", path: "path1", memberOf:"g_2" } }],
groups: [
{g_1 : {group: {conjunction: "OR"}}},
{g_2 : {group: {memberOf: "g_1", conjunction: "AND"}}}
],
limit: 10,
offset: 1,
sort: "-body"
})
}
}
getNodeByRouter:
- Your front-end page should be a Drupal subdomain.
- Install module in Drupal:
- "Decoupled Router" (https://www.drupal.org/project/decoupled_router)
- "Subrequests" (https://www.drupal.org/project/subrequests)
composer require drupal/subrequests
- drupal_connector_helper (https://github.com/dongpd1994/drupal_connector_helper)
import React, { Component } from 'react'
import Drupal from 'drupal-connector'
const ConnectionDrupal = new Drupal({
baseUrl: 'http://drupal.dd:8083/'
})
const fetchData = async () => {
const node = await ConnectionDrupal.getNodeByRouter('alias-url')
.catch((error) => {
console.log(error.message)
})
.then((response) => {
return response
})
}
Field component:
Name | Description | Type | Required |
---|---|---|---|
include | The included response of API get content data | object | true |
value | The value of field | object | true |
basePath | If field is image, file then basePath is url of Drupal | string | false |
import React, { Component } from 'react';
import Drupal, { FieldBoolean } from 'drupal-connector';
...
render(
<FieldBoolean
data={{
include: {},
value: {}
}}
basePath="http://drupal.web.dd:8083"
/>
)
MIT © dongpd1994