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().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Title: clean up Flagging CRUD methods » field_attach_presave() is called too late
Issue summary: View changes
Parent issue: » #2202969: clean up flag() and its low-level helpers
joachim’s picture

In 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.

joachim’s picture

Status: Active » Needs review
FileSize
1.85 KB

This won't affect FlagHookInvocationsTestCase because that doesn't test the hook_field_attach_FOO() hooks.

joachim’s picture

Status: Needs review » Fixed

  • Commit 730e385 on 7.x-3.x by joachim:
    Issue #2121053 by joachim: Fixed field_attach_presave() getting called...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.