Event Handlers - Mura Docs v7.1

Event Handlers

Mura event handlers are simply ColdFusion components (CFCs), or files saved with the extension .cfc. They contain methods/functions, and may contain other variables and/or data. Most event handlers will contain one or more of Mura's event hooks, and/or custom event hooks.

The event hooks are merely "announced" during specific points of a request. Registered event handlers will be parsed when the event they're registered for occurs, and if any event hooks are found, they will be executed. For example, if you have two registered even handlers, and both of them contain a method listening for the same event hook, both methods will execute, whenever the event is announced.

As described in the Standard Events section, Mura's standard events handler is located under {context}/core/mura/Handler/standardEventsHandler.cfc. The methods may be viewed via Mura's Component API at http://www.getmura.com/component-api/7.1/index.html?mura/Handler/standardEventsHandler.html.

Developers may have several Mura event handlers throughout your sites, themes, content types, modules, and plugins. As of Mura v7.1, you may also register your event handler(s) for specific entities. In addition, you can choose to register your event handlers by convention, or explicitly register them via a known event handler. Examples and options are described below.

Example Event Handler

With the exception of the "Site" event handler, or the "Theme" event handler, you can name your event handler anything you want, as long as it has the .cfc file extension. All event handlers should extend mura.cfobject. By doing so, you allow yourself the ability to leverage many of Mura's baked-in methods and functionality for working with Mura objects.

CFScript-based .CFC Example

component extends="mura.cfobject" {

  public any function onSomeEvent(m) {
    // arguments.m is "The Mura Scope"
    // Do something


Tag-based .CFC Example

<cfcomponent extends="mura.cfobject" output="false">

  <cffunction name="onSomeEvent" access="public" returntype="any">
    <cfargument name="m" hint="Mura Scope">
    <!--- Do something --->


Plugin Event Handlers

Plugin event handlers should extend mura.plugin.pluginGenericEventHandler, instead of using the typical mura.cfobject. Doing so allows you access to the plugin's own configuration information via variables.pluginConfig, as well as Mura's configuration data via variables.configBean.

Registering event handlers in plugins is covered in the Plugins section.