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
FieldItem::delete is being called in two cases:
1. When the whole entity is being deleted - for all translatable and non-translatable fields.
2. When a translation is removed - for all translatable fields of the removed translation.
However we are unable of determining if the parent is being deleted or only a translation is being removed from it.
Proposed resolution
Add a parameter to FieldItem::delete to specify the action we are currently doing.
Remaining tasks
User interface changes
API changes
Data model changes
Problem/Motivation
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#23 | 2834384-nr-bot.txt | 144 bytes | needs-review-queue-bot |
#13 | 2834384-13.patch | 8.76 KB | idebr |
#13 | interdiff-7-13.txt | 899 bytes | idebr |
Comments
Comment #2
hchonovComment #3
BerdirThe problem is that even an optional argument is a BC change because all implementations are forced to implement it.
Maybe we can think of something that allows to identify this case in an uglier but backwards compatible way. A flag on the entity object for example.
Comment #4
hchonovYou are right, but I am not really a fan of setting dynamically a property on the entity as this involves the magic getter and setter. What if we call the delete method with a parameter without defining it in the interface until D9, but provide test for this and in D9 put the parameter into the interface?
Comment #5
BerdirThat might work, nice idea.
Comment #6
hchonovComment #7
hchonovI've added also a test for the non-translatable field.
Comment #8
BerdirWe should document this somehow. Possibly add a paragraph on the interface and explain that the argument exists but is not enforced in the interface, with a @todo to add it in 9.x
of course that means that not passing the argument along could then result in bugs in code that relies on it :(
Comment #9
hchonov1. This is probably the better way.
2. Well you are right but we actually already have such an inconsistency with the $include_computed parameter so without defining the parameter in the interface there is no other way around this.
Comment #13
idebr CreditAttribution: idebr at iO commentedReroll against 8.6.x and implemented the following changes:
#8.1 Added documentation to \Drupal\Core\Field\FieldItemInterface::delete() that it is called with an additional '$parent_delete' parameter that is not enforced through the interface.
#8.2 Not sure on the implications here. I have been unable to find any implementations of FieldItemInterface::delete outside of Drupal core.
Comment #23
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.