Problem/Motivation
Split off as a @todo for an obscure edge case of #2570593: Allow entities to be subclassed using "bundle classes"
At https://git.drupalcode.org/project/drupal/-/merge_requests/200#note_14489 @alexpott asks:
What happens if the preCreate sets a bundle that is altered to use a class. That's not going to work - right?
@berdir adds:
[I]t does mean that you couldn't provide a bundle class for the default bundle, which might or might not be fine. We could call getBundleFromValues() a second time after calling preCreate(), there's still an edge case where that class would implement preCreate() too, but we can't have everything? But minor, fine with me if we skip that.
And @larowlan asks:
could we throw an exception if the bundle was non empty in $values but changed in preCreate?
Steps to reproduce
TBD. I think:
- Install a version of Drupal that includes #2570593: Allow entities to be subclassed using "bundle classes" (or apply the latest patch there).
- Register a bundle class for 'article' nodes.
- Define a preCreate() method in the bundle class.
- Swap out the bundle you're dealing with.
- Notice that you can't change which class is registered as the bundle class this way.
Proposed resolution
TBD
Remaining tasks
- Decide what to do.
- Do it.
- Write / update tests.
- Reviews / refinements.
- RTBC.
Comments
Comment #2
dwwComment #3
larowlan