Wednesday, October 24, 2012

Packaging Drupal Rules into a Module

The Rules module comes with a nice Import/Export feature which makes it easy to move complicated sets of rules from one environment to another without a bunch of unnecessary re-configuration.  The simplest way is to simply copy the code out of the 'export' page ( an array ), and paste it into the 'Import' page on the target installation.

An even cooler way to move rules and be sure they're available to custom modules that depend on them is to include hook_rules_defaults() in your module code.

An example would look like this:

function hook_rules_defaults() {
   $rules = // paste the exported rules array here and add a ';' at the end of the array

   return $rules;
}

When the module is installed, so are the rules outlined in the array.

No comments:

Post a Comment