Follow-up to #2162925: Passing NULL to entity hooks. My comment there:

I think part of the problem here is that with the advent of flagging entities in 3.x, the flag() method has gained a 3rd purpose, which is pretty much undocumented:

- you want to flag a thing
- you want to unflag a thing
- you want to update the flagging on a thing

The thing about the 3rd purpose, the update of the flagging, is that the flagging object itself is never updated! This is for the simple reason that there are no properties in the {flagging} table that you can update: there is no 'changed' timestamp, and if you want to change anything else (such as the uid, the entity id, the flag id) then you are actually wanting to unflag and then make a completely new flagging.

Therefore, when you use flag() to update a flagging, while the Field API fields on the flagging can get updated, the flagging table is not, and the flagging object itself is not saved!

This raises an interesting question about whether hook_entity_presave() should even be called in this case! I'm going to say that it should, since the fields are updated, and everywhere in Entity and Field API you have to save an entity to save fields. Therefore, we are in principle updating the Flagging entity, even if we're not bothering to update the {flagging} database table -- this can be viewed as a mere performance enhancement.

I'm going to add some explanations at the places where the hooks are invoked.

Comments

joachim’s picture

Status: Active » Fixed
StatusFileSize
new1.04 KB

Status: Fixed » Closed (fixed)

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