logo services about us contact
 

Drupal Hooks, Modules


Drupal offers a system of callback hooks at various parts of the core code. The hooks are placed in key locations within the core code, such as when adding a user. When the core code hits a hook, it will call out to all implementers of a given hook, finding implementers by looking for method names that adhere to a naming scheme (replace the word 'hook' in the hook's name with name of your module). These implementing methods are placed in "modules" that are just PHP files that also follow a particular file-naming scheme (*.module) and are placed in particular directories (sites/all/modules/*).

Workflow-ng

A module workflow-ng, for example, implements several hooks that fire when users and posts are created, updated, deleted, etc. Workflow-ng offers a GUI configuration screen that can configure Drupal to do such actions as sending an email somewhere when a new user is registered. Workflow-ng even creates its own hooks for callback, and employs its own kind of module system using a ".inc" filename suffix for implementers of callback functions.

The actions in Workflow-ng include setting the author, changing status (e.g., to published), scheduling an event, etc. There is no action in Workflow-ng to execute arbitrary PHP code, but there is a request for it.

One way to get events from Drupal would be to implement that 'arbitrary PHP code' feature, then use it to send events into an ActiveMQ (JMS) message broker. A similar event broker is MantaRay.

Another alternative would be to add an action to Workflow-ng that sends a message to some pre-configured message broker for each event of interest.

Writing module for events

Cutting out the workflow-ng association, one could write a module that directly sends events to any pre-configured message broker. This module development would show a configuration screen like the workflow-ng, but the only action would be to turn on the flow of messages. Some configuration would available for specifying the URL for the message broker, and perhaps configuration would be added for constructing the individual messages payload. However, it is likely that the any available information about the event would always be sent in its entirety in a message payload.

Using the Stomp protocol to JMS

See notes on getting the Stomp protocol to work to connect php and JMS. That page's comments can be summarized:

  • PHP needs the socket extension (not default on windows)
  • Stomp implementation has some deprecations (turn on PHP error display or check logging)

The msgqueue Module for Drupal

The msgqueue module is a sample of how this all would work in practice.

 

Creative Commons License
This page is licensed under a Creative Commons License.

  services about us contact
©2000-2007 Codeguild, Inc.
Codeguild is a service mark of Codeguild, Inc.