I have made 2 custom tokens that I use to determine the URL alias in the Pathauto pattern. They work fine too, but since my custom tokens rely on certain (taxonomy) fields in the node, they always get the "old" field value when the user changes them. The url alias isn't correct until the second time I save the node. Thus I need to "presave" the node immediately when the user changes the field value, so that the new token value is taken into consideration when saving the node... How can I do that?
Since the change is done on the client side I would need to use Ajax to call node_save or hook_node_presave directly when the field value is changed?
Any help is appreciated :-)
EDITED: I have realized that I probably need to write a JS script that uses ajax to call a php function that saves the node when the field is changed. So the question now is if that is wise to do when the user is in the editing mode… ?
I finally worked it out. I skipped the JS solution and opted for using field_attach_presave('node', $node) and field_attach_update('node', $node) in the function hook_node_presave. Doing so permits to save 2 specific fields programmatically just before the node is saved definitely by the user. And Pathauto can use those 2 fields as tokens for my URLs. It works too :-). There are many reasons for this non straight-forward solution, a bit to lengthy to explain here (migration is involved among other tings). But I am happy with this solution. Thanks for the input though!