Difference is usage of register_error()+forward() vs. return elgg_error_response()????

When making new plugin releases I'm currently replacing all usages of register_error()+forward() with return elgg_error_response() (and the same with success handling) in actions. Now I already found out today that this doesn't work for example when overriding the plugin settings save action and it seems I came across another case where it fails at

https://github.com/iionly/izap_videos/blob/dd943ea094b3abc2c631020dc95c830ea2e7c620/actions/izap_videos/ONSERVER.php#L27

This file is included by the action https://github.com/iionly/izap_videos/blob/master/actions/izap_videos/addEdit.php for on-server uploads. With the "old" way the action was cancelled and I got redirected to the upload form with an error message. Fine.

But with return elgg_error_response() it seems the action is not cancelled. Am I only returned to the addEdit action from where ONSERVER.php got included and the following code is executed then?

If that's the case, would I have to continue to use the old way? I'm kind of unsure now when to use which approach. I also would like to know how sustainable it is to leave it the old way. Will it still work on Elgg 3 or would it be necessary to change the code then? If so, how is it supposed to be?

  • As it seems the include might be the problem here. The return within the included file would result in continuation of execution of code after the include statement.

    Would it be the correct way then to use elgg_error_response + forward?

  • If you do "return include $another_action;" that should work. forward() sends redirect headers, where as returning from action file simply terminates the action file. As much as I'd love to remove it, I think it's here to stay, so you can continue using it, if it does the job.