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.
In node:
node_invoke($node, 'delete');
module_invoke_all('node_delete', $node);
module_invoke_all('entity_delete', $node, 'node');
field_attach_delete('node', $node);
In flag:
field_attach_delete('flagging', $flagging);
// Remove from the cache.
entity_get_controller('flagging')->resetCache();
// Invoke hook_entity_delete().
module_invoke_all('entity_delete', $flagging, 'flagging');
Data should still be available when hook_entity_delete() is invoked, so implementations can make use of it.
Comment | File | Size | Author |
---|---|---|---|
#8 | flag-2196085-8.patch | 1.05 KB | cs_shadow |
#6 | flag-2196085-6.patch | 1.12 KB | cs_shadow |
#4 | flag-2196085-4.patch | 1.08 KB | cs_shadow |
#2 | flag-2196085-2.patch | 705 bytes | cs_shadow |
Comments
Comment #1
joachim CreditAttribution: joachim commentedComment #2
cs_shadow CreditAttribution: cs_shadow commentedAttaching a quick patch where
hook_entity_delete()
is invoked before deleting field data. Also added a short comment forfield_attach_delete
, if that helps to understand the code better.Comment #3
joachim CreditAttribution: joachim commentedThis is going to need a reroll due to the refactoring that took place in #2202969: clean up flag() and its low-level helpers. I should have marked this as postponed until that one was fixed -- sorry!
Comment #4
cs_shadow CreditAttribution: cs_shadow commentedRerolled the patch against latest HEAD.
Comment #5
joachim CreditAttribution: joachim commentedThanks for working on a patch!
I'm not sure the order is right. The entity should still exist in the DB when field API and hooks are invoked.
Look at node_delete() -- we should do the same as that, for consistency.
Comment #6
cs_shadow CreditAttribution: cs_shadow commentedChanged the order as in node_delete().
Order in node_delete:
New order in flag:
Comment #7
joachim CreditAttribution: joachim commentedThat's not node_delete(), that's the code for deleting a node *type*.
Though node_delete() just calls https://api.drupal.org/api/drupal/modules!node!node.module/function/node.... But that definitely deletes the record after invoking hooks.
Comment #8
cs_shadow CreditAttribution: cs_shadow commentedSorry, looked at the wrong function earlier. This one follows the order of deleting nodes. Now the order is:
Comment #9
joachim CreditAttribution: joachim commentedPerfect! Thanks for working on this.
Comment #11
cs_shadow CreditAttribution: cs_shadow commented@joachim thanks! Finally got it right.