Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
In \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::onDependencyRemoval() we trigger a critical error if all the bundles are removed. This is the incorrect behaviour because this method is called to work out what is going to change in a "dry run" mode so it is logging critical errors for things that have not actually happened.
Proposed resolution
Move the log message to field_field_config_presave().
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#11 | 2925913-11.patch | 10.42 KB | alexpott |
#11 | 8-11-interdiff.txt | 781 bytes | alexpott |
#8 | 2925913-8.patch | 10.42 KB | alexpott |
#4 | 2-4-interdiff.txt | 8.88 KB | alexpott |
#4 | 2925913-4.patch | 11.65 KB | alexpott |
Comments
Comment #2
alexpottLet's see what and if anything breaks.
Comment #3
alexpottComment #4
alexpottFixing a couple of tests and making
field_entity_bundle_delete()
work the same way - if the entity type that the reference field is referencing has no bundles then the field can't exist because there's nothing to reference. As the old log message used to say - the field is broken. We shouldn't be leaving broken configuration around.Comment #6
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedAs far as I remember from #2412569: Allow setting the auto-create bundle on entity reference fields with multiple target bundles, this is not about the referenced entity having no bundles, it's about the last configured *target bundle* being deleted. It's also what is being explained by this comment that you are removing:
The default behavior of the entity reference field when there are no specific target bundles configured is to reference *all* bundles of the target entity type, that's what we're trying to prevent with that log message.
Comment #7
alexpott@amateescu pointed out that history here is actually in #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted
Comment #8
alexpottSlight different approach after reading #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted. This maintains the critical error it just moves it's generation to field_field_config_presave() since at this point we know that the field is being saved with an empty
target_bundles
setting. @amateescu mentioned that an empty array might mean all bundles - actually it doesn't that's what a NULL means and is part of the change introduced by #1978714: Entity reference doesn't update its field settings when referenced entity bundles are deleted. @amateescu also pointed out my incorrect assumption that removing the bundle meant that there were not more possible bundles. This is not correct there might be its just that the field might not have been configured to use them. The new approach prevents dry run calls to onDependencyRemoval logging incorrect critical errors but still maintains the error is you do end up with an entity reference field that's configured withtarget_bundles
as an empty array and hence can actually reference nothing.No interdiff because this is a new approach.
Comment #9
alexpottComment #10
alexpottComment #11
alexpottFix the comment to make more sense - we've not deleted a bundle in the code that is being referenced.
Comment #12
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThat looks much better! Thanks @alexpott :)
Comment #13
catchCommitted/pushed to 8.5.x and cherry-picked to 8.4.x. Thanks!