The Drupal 8 External Entities Module: How to Retrieve Remote Data and Display It on Your Drupal Site

The Drupal 8 External Entities Module: How to Retrieve Remote Data and Display It on Your Drupal Site

It's no groundbreaking news for anyone anymore: Drupal 8's database agnostic and it comes with a drastically improved core entity API. This allows it to interact with remote data stored in pretty much any type of external database. In this respect, there's a whole array of contributed modules that you can use for retrieving and integrating external content into your Drupal website. Now the new challenge that arises is: what if you wanted to display that external data as... Drupal entities? And this is precisely where the Drupal 8 External Entities module steps in!

Basically, this module enables you to use that data, collected from various external sources, to create more of “Drupal-like” type of experiences. Meaning to expose it as view modes, permissions, Drupal entities, form modes etc.

It allows you to set up a simple back-end and expose the retrieved data (from a Json file, an internal SQL-database, or any other type of remote database) as Drupal entities on your Drupal 8 website.

And now, let's get into more details on how this module works more precisely:

1. But First, Let's Define “External”: External Data, External Data Source...

“What stands for a remote data source?” you might ask yourself.

Let me give you a few examples:

  • REST API endpoints
  • spreadsheets
  • web scrapping
  • external database
  • files
  • sensors

Practically, the remote data that your Drupal 8 website can retrieve and display ranges from:

  • Wikipedia content
  • to specific systems used within your company
  • to different online catalogs (e.g. a museum's exhibition catalog)

And the list is endless...

Note: if you've managed to write a robust-enough back-end, you'll even get to apply changes to these remote content entities. 

2. The Drupal 8 External Entities Module: Quick Overview

If I am to sum up this module's role, into just a few words, it would go something like this:

It enables your Drupal 8 website to interact with datasets from remote databases and easily display/use them.

Not just anyhow, but:

As Drupal entities!

Basically, your Drupal 8 website will take those external entities as “internal”, allowing you to:

  • add comments
  • apply changes to the field displays
  • add references
  • add share buttons

And so on...

It's a familiar experience that you/your team will enjoy, with Drupal entities, Drupal-specific concepts (form modes, permissions, view modes...) to “juggle with”.

Now here are a few “kindred” modules that you might find useful in your attempt to make your Drupal site connect and interact with external data sources:

  • Feeds
  • Data
  • Web Service Clients (D7)
  • Remote Entity API (D7)

3. How Does It Work?

The whole process “behind the curtains” can be summed up into one basic sequence of actions:

The Drupal 8 External Entities module provides an entity type within which you get to define bundles.

As for the back-end needed to support the process of displaying the retrieved data as Drupal entities, it's a REST back-end that the module currently uses. Yet, you're free to integrate other back-end types, as well, considering that they're just... plugins.

4. If It Hadn't Been for The 2 Major Improvements in Drupal 8...

… the Drupal 8 External Entities module wouldn't have been built.

But, since:

  1. Drupal 8's Entity API can now leverage all its massive improvements
  2. Drupal 8 is database agnostic; it retrieves data stored in any type of source, anywhere 

we can now use external entities to share data among multiple Drupal 8 websites using the very same remote database. 

No more synchronization as the main method for sharing content between multiple sites (e.g. the Deploy module). An otherwise cumbersome method requesting multiple copies of the same content to be updated each time the source data got updated.

Moreover, we're now able to pull data from remote data sources and expose it as Drupal entities on our websites. Drupal 8's created the right context for that...

The END!

So, are you curious enough to leverage these capabilities that Drupal 8's been equipped with for interacting with remote data, that it perceives as... internal entities?

Photo by Randall Bruder on Unsplash