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.
Comments
Comment #2
joachim CreditAttribution: joachim commentedComment #3
bojanz CreditAttribution: bojanz at Centarro commented1. 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?
Comment #4
joachim CreditAttribution: joachim commented> 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.
Comment #5
bojanz CreditAttribution: bojanz at Centarro commentedOkay, let's proceed then.
Comment #6
joachim CreditAttribution: joachim commentedComment #8
bojanz CreditAttribution: bojanz at Centarro commentedConverted the strtr to a sprintf and committed. Thanks!