If an entity using bundle plugins doesn't have a 'bundle' entity key, bad and confusing things happen.

This is because parts of the entity system fall back on the bundle being the same as the entity type ID if there is no 'bundle' entity key defined.

That means that when field definitions are loaded, the bundle plugin system tries to load a plugin whose ID is the same as the entity type ID. That plugin probably doesn't exist.

So the developer gets a confusing exception about a plugin that doesn't exist, when the problem is somewhere else entirely.

We can catch this exception earlier for better DX.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim created an issue. See original summary.

joachim’s picture

bojanz’s picture

Status: Needs review » Needs work

1. No longer applies.
2. strtr() should be replaced by sprintf() to match core and other contrib.
3. I am a bit nervous about throwing an exception while building the entity definitions. Can't we do it in a service? Where does the tricky behavior originate? BundlePluginHandler?

joachim’s picture

> 3. I am a bit nervous about throwing an exception while building the entity definitions. Can't we do it in a service? Where does the tricky behavior originate? BundlePluginHandler?

No, it's simply if you define your entity type to use bundle plugins, but forget to specify a bundle entity key. Which is what I did :) IIRC everything goes totally haywire. Hence this exception would crash a 'drush cr' with a clear message that you've messed up your code.

bojanz’s picture

Okay, let's proceed then.

joachim’s picture

  • bojanz committed 8891a50 on 8.x-1.x authored by joachim
    Issue #3028820 by joachim: throw an exception if an entity using bundle...
bojanz’s picture

Status: Needs review » Fixed

Converted the strtr to a sprintf and committed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.