wiki:FAQFilterRedirectTriggerPreProcess

Redirecting from a Filter and ensuring Pre-Process plugin points are triggered

The central method of any Mach-II event-filter component, is the filterEvent() method. This method, which is automatically called by Mach-II whenever the filter is called, is automatically passed three arguments by the framework:

  • the event object
  • the current eventContext object
  • a struct of paramArgs

The fact that these arguments are passed into our filterEvent() method gives us a considerable amount of control regarding the actions we can take within the method. One common technique used within a filter is to redirect a user to another event based on the specifics of the request. For example, the current user does not have admin privileges and is attempting to access an admin only event. In this case, one solution would be to clear the event queue by calling arguments.eventContext.clearEventQueue() and then announcing a new event by calling the announceEvent() method. The announceEvent() method is available from within the filter since it is a method of the Mach-II BaseComponent, which is the parent component of all Mach-II framework components.

When announcing a new event in this manner, however, the pre-process point of the new event is not executed. This can be problematic if you have some functionality in a plugin which should execute at the pre-process point on new event. In order to address this, one option is to announce a new event which has the sole purpose of redirecting to the actual event of interest. In this way, each plugin point on the new event will be announced in the expected manner.

Sample code:

<event-handler name="redirectEvent">
  <redirect event="realEventToAnnounce"/>
</event-handler>