Integrating with Drupal

When integrating with Drupal, there are a lot of things to think about and consider:

1. Data structures

2. Communication

3. Permissions

4. Caching

Data Structure

There are many different tools in Drupal 8 for storing data, such as: content types, paragraphs, custom entities, taxonomies, etc. Any of these can be utilized for an integration. This stage is highly dependent on what the integration needs. Content types are going to be displayed as pages, so if the information for the integration doesn't need a page than this might not be the best option. The ability to create a custom entity is extremely powerful. This entity allows you to build your data however it is needed and to easily create admin interfaces. After deciding what information is needed to store, you will then need to figure out how to store the information. This means using the correct fields: storing integers as integers, text as text, and using entity references of paragraphs. Planning and laying out the information in the best format will make integration much easier.


How is this integration going to communicate with Drupal? There are multiple options to do this, such as: custom route, rest API, feeds, and views. You will need to figure out what works best for the integration. Creating a custom route for creating just one complicated feed may be the best. If multiple end points are needed, maybe using the Rest API to easily create these would work best. Maybe the integration requires Drupal to pull information and store it rather than supplying the information. The Feeds module, which is still in dev, allows you create imports of content. Think about what the integration needs and what will provide the integration the most use.


This is more than just access to an endpoint. This covers if users are allowed access to the data in Drupal or even edit this data. This relates a lot back to how you store your data. Content types and custom entities can easily use Drupal's permissions. Endpoints are more difficult to assign permissions to. Drupal's Rest API has different authentication methods to use. Creating a custom route will require creating a custom permission by using a key passed through a parameter as an example.


For example, if the integration is supplying content to a mobile app, caching could greatly increase the speed of the site and app. Once the output has been built, it's time to think about caching. What is the data reliant on? A node, a custom entity, or perhaps its own metric. This is where adding cacheable dependencies to the response object comes in use. Adding something like a node as a cacheable dependency will let Drupal know it needs to update the response if the cache is older than the last modified of the node. Depending on your integrations needs, it's possible to build a custom cacheable dependency as well.