They way the hooks are triggered, it’s quite easy to create an infinite loop.
For example, say you use the after_channel_entry_save hook to update another entry’s data. If, in your extension, you use a Model to change the data of that entry, that entry’s hook will fire.
This can also occur if you change an entry in a field type’s post_save method.
I’m sure you could work around the issue, but I reckon it’s fairly easy (maybe too easy) to create infinite loops like this.
We discussed it while building them, but there is no good way around it. If it fires on all data manipulations, which is what we want, people will find bad ways to manipulate that data and cause loops.
Both the extensions library and the models themselves try to mitigate those problems, but at the end of the day you could do it with the old hooks as well.
The easiest way to avoid them is to prefer the before* hooks. Modifications in there will get saved automatically.
I’m currently seeing this in a custom field type, where I want to change the entry’s entry/expiration dates based on the field type’s value. Right now, I’m doing this in the post_save method. I would do this in the save method instead, but I don’t have access to the parent entry then. So…
FR: a way to manipulate the Entry model in the save method of a field type.
For now, I’ll just continue using Active Record to change those values.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.