This is something I noticed while reviewing #2119467: Invoke entity CRUD hooks.
We call field_attach_presave() AFTER we've saved data. That's surely not right.
I think we need to clean up all of this part of the flag code:
- the _flagging_insert/update/delete() methods are all only called once, so I don't think they are necessary. They don't simplify the code (you have to jump around to follow the flow), and they have clearly led to bugs in the case of field_attach_presave().
- review the order in which all the various things are called, and check it makes sense in comparison with core entities
-- field_FOO API functions
-- entity CRUD hooks
-- Rules
-- our own hooks
- fold in the private methods _flag() and _unflag(). Again, they are only called from one place and just cause the flow the jump around. Also, _flag() should be converted to use drupal_write_record().
Comment | File | Size | Author |
---|---|---|---|
#3 | 2121053.flag_.field_attach_presave-order.patch | 1.85 KB | joachim |
Comments
Comment #1
joachim CreditAttribution: joachim commentedComment #2
joachim CreditAttribution: joachim commentedIn both https://api.drupal.org/api/drupal/modules!node!node.module/function/node... and https://api.drupal.org/api/drupal/modules!taxonomy!taxonomy.module/funct... the order is:
- field_attach_presave()
- hook_ENTITYTYPE_presave()
- hook_entity_presave()
and the same for the FOO_insert() and FOO_update() set.
We don't supply hook_flagging_FOO() hooks (because we have our own hooks for reacting for flagging/unflagging), but we should follow the same order as core for the hooks we do invoke.
Comment #3
joachim CreditAttribution: joachim commentedThis won't affect FlagHookInvocationsTestCase because that doesn't test the hook_field_attach_FOO() hooks.
Comment #4
joachim CreditAttribution: joachim commented