Entities Elsewhere

Ron Northcutt

Sr. Solutions Architect

Acquia

Video at: https://www.youtube.com/watch?v=ElAYGMuCVJw

Who am i?

  • using Drupal since 4.7
  • freelance developer
  • small dev shop
  • sr. developer & tech lead
  • sr. solutions architect

Find me online:

Agenda

  • Overview
  • Entity storage
  • External entity module
  • Custom storage handler
  • Next steps
  • QA

Warning: Going off the map.

Buckle up...

Overview

  • Using Entity API
  • Changing the storage handler
  • That's basically it*

*The devil's in the details

Note: there are alot of details...

Entity Storage

Drupal 7

  • Field API introduced the concept of swappable field storage

  • Field data can live anywhere 

    • Remote DB
    • More performant DB
    • Eg. NoSQL for some things
  • Problem with querying
    • Fields might be in different backends
    • Tough or impossible in some cases

Drupal 8

  • Changed from field-based storage to entity-based storage

  • Field data on an entity share the same backend

  • Querying becomes more practical
  • This is why we lost field sharing between entities
    • Eg. address on user vs. address on node

Drupal 8

  • Each entity type has a dedicated storage handler

  • Responsible for loading, storing, and deleting field data 

  • Defined on the entity type definition 

  • Can also be changed with hook_entity_type_alter() 

This is the key!

External Entity module

  • https://www.drupal.org/project/external_entities
  • More of a test/dev/example
  • Provides a entity type and allows you to define bundles
  • Each bundle = external config options
  • Map fields to the external data

Demo

Custom storage handler

Diving into code

Demo

Next steps

  • Query API options
  • Better form integration
  • Better support in core?
  • More people using this approach

Tips

  • Look at the Storage handles in code
  • Consider Key/Value instead of content entity
  • PHPStorm + Xdebug FTW
  • Take your time - this is some wacky stuff

Homework

  • Talk to people about this approach

  • Play with the External Entity module

  • Review other webinars, tutorials, and videos

  • Contribute and make it better!

Questions?

Entities Elsewhere

By Ron Northcutt

Entities Elsewhere

External entities in Drupal - Texas Camp 2017

  • 919