3

I'm just getting my feet wet with Drupal 8, having written a decent amount of modules for various projects for Drupal 6 and 7. We are trying to leverage Drupal as a CMS add-on to our club management software. A lot of our customers have asked us both how we would integrate into an external system and also how we could provide customer websites. We've decided to try and leverage Drupal 8 to provide a hosted CMS to our customers.

We are developing a REST API for our product that will expose various resources such as Events, Equipment items, Equipment Reservations, etc... What we want to do is have those available in Drupal, preferably as full-fledged entities so that customers could add additional information to these items that is stored with Drupal. For an example, we would provide an Event object via our API and then a customer could add a "photo gallery" field in Drupal to add photos to the event.

We'd also show an events and equipment usage calendars using data from our product, likely as blocks.

What I'm somewhat stuck on is how to define an Entity without storing it in the SQL database. We want our system (via REST) to be the canonical source with addons and UI provided by Drupal.

Can anyone point me in the right direction as to how I could create an entity type with its core storage outside of Drupal and linked via an API?

I should note, I already found the External Entities module, but I don't see how it exposes the external entities as viewable or fieldable objects. Perhaps I'm just missing something here?

Thanks in advance!

  • I should also mention that we don't want to do a one-time import, but rather query them on display (likely with some caching) so if things change on our end they are properly reflected in Drupal. – Justin Cherniak Jan 4 '16 at 21:32
3

I haven't looked at that module yet, but pretty much everything that involves the storage of an entity goes through the storage handler of a given entity type.

Drupal 8 provides to real implementations, SqlContentEntityStorage for content entities stored in the database and ConfigEntityStorage for config entities stored in configuration. And a few test and example implementations too.

So the first thing you need to implement is your own storage. Do whatever you want in the relevant methods like load()/save()/delete(), see EntityStorageInterface.

Additionally, you will have to implement a entity query, so you can create lists with conditions, sorts and so on. That also comes from storage (getQuery()), initialized based on a given service name, see for example entity.query.sql and entity.query.config. That's a factory that returns the actual query object and in there, you can again do whatever you want. For content entities, it's transformed to an SQL query while config entity queries are actually mostly implemented in PHP, with some optimizations and lookups.

If you also want to use views, you have to write a backend for that too, since it doesn't use entity query (yet). There's https://www.drupal.org/project/efq_views, not sure how far it is for Drupal 8.

0

If you just want the external data to be read and display in your site then you can use this module, View xml Backend, Views will have the external data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.