I was looking for a way to act on entity fields before they are saved, and I have noticed the following about hook_field_attach_presave(), and hook_entity_presave():
- They take the same parameters, but in a different order.
They are both called when an entity is saved. For example, taxonomy_term_save() contains the following code.
// Invoke hook_field_attach_presave(). field_attach_presave('taxonomy_term', $term); module_invoke_all('taxonomy_term_presave', $term); module_invoke_all('entity_presave', $term, 'taxonomy_term');
Similar code is present in comment_save().
field_attach_presave('comment', $comment); // Allow modules to alter the comment before saving. module_invoke_all('comment_presave', $comment); module_invoke_all('entity_presave', $comment, 'comment');
As they get the same parameters, the code I should write to access the entity's fields is the same for both the hooks. This means that, apparently, there isn't any reason to choose one instead of the other hook.
When should I then implement one hook instead of the other? Are there cases where I would implement