Proposal: Entity Reference fields with Dynamic Entity Reference in 8.2

jibran
larowlan

Drupal 8 comes with Entity Reference in core, but there is one limitation of this field - it cannot reference more than one entity type at a time.

In core, in order to deal with this issue - we have work arounds, for example the Comment entity needs to reference its host, to do so it has two fields in the base table, one for entity ID and one for entity type. As this isn't how Entity Reference fields in core currently work, comment module has to do some juggling to ensure chaining of entity-references work (see Comment::bundleFieldDefinitions).

Similarly in core we have a UI for associating a menu-link with a piece of content, but at the moment this is only limited to nodes; as the entity reference field cannot reference more than one entity type. So if you need to create menu links to e.g. users or commerce products for example, these can only be done using the user scheme, meaning you can fast end up with orphans. Something that isn't possible with a reference.

Noticing these issues and driven by requirements for contrib, @jibran and @larowlan have built an enhanced entity-reference field - dynamic entity reference. This allows one field to reference multiple entity types, and opens a world of possibilities for data modelling.

The module is already flagged for use in contrib modules like UserPoints where each point awarded needs to store a reference to more than one entity-type associated with the event from which the points were granted. In additon the module drives the 'passengers' field in the soon to be released 'Entity Pilot' content staging system, allowing content-editors to build up a list of content to stage that contains more than one entity-type

It already has built-in Views integration for the module, which opens the door to a world of interesting possibilities and building killer site features like activity streams spanning nodes and comments in a single view.

In this session
  • will introduce DER and discuss its APIs, demonstrating its feature parity with existing ER fields, formatters and widgets in core.
  • will demonstrate the validation and typed-data implementations
  • will demonstrate the views capabilities
  • will show updated menu-link ui using dynamic entity reference widget.
  • will open the floor to discuss the pros and cons of considering DER as a drop in replacement for ER in a future 8.x point release.
  • will discuss how the usability can be improved.
About the presenters

Jibran Ijaz (@jibran)

  • Has been working with Drupal for more then 4 years.
  • Has more then 200 commit mentions in Drupal 8.
  • Has reviewed a lot Drupal 8 patches.
  • Has worked on a lot Views patches in Drupal 8.
  • Is the maintainer of Views field view, Views fieldset style plugin, Views details style plugin, Views vertical tabs style plugin and Views collapsible group.

Lee Rowlands (@larowlan) (remote via Hangout)

  • Has been working with Drupal for over 6 years
  • Is a member of the Drupal security team
  • Is the core maintainer of comment, forum, contact and block content modules
  • Is a top 20 contributor to Drupal 8

Session Track

Core Conversations

Experience Level

Intermediate

Drupal Version