Porting Reaction Rules

Last updated on
11 December 2021

Reaction Rules collect configured events, conditions, and actions into a bundle to accomplish a specific task. Reaction rules react to selected events on the site. Each reaction rule may fire any number of actions, and may have any number of conditions that must be met for the actions to be executed.

These are the steps for porting reaction rules to Drupal 8/9:

Tasks

  1. Make a list of reaction Rules that you module provides. These may be found at /admin/config/workflow/rules on your Drupal 7 site. Rules shown in the "Active rules" section of that page are essential for normal functionality, while those shown in the "Inactive rules" section are optional and provided for your convenience - many times they perform frequently-needed actions that are not part of the module's default functionality.
  2. Reaction rules are defined in D7 by code found in hook_default_rules_configuration(), or by creating an instance of rules_reaction_rule() and programmatically adding pre-existing events, conditions, and/or actions to it. This hook usually may be found in <modulename>/<modulename>.rules.inc (although, some modules implement this hook in <modulename>/<modulename>.module instead). Refer to the D7 version of this file to ensure that you port ALL the events that were in D7.
  3. Create configuration files for these Rules in D8. Configuration files should go into <modulename>/config/optional/ and be named rules.reaction.<rule machine name>.yml You can do this by using the Rules UI in D8 to recreate the reaction rules you see in D7, then go to /admin/config/development/configuration and export the configuration file for the rule you just made. (You must enable the core Configuration Manager module to export in this manner. See Exporting Reaction Rules for more details.
  4. Manually test, in the Rules UI, that each reaction rule shows up and has the same arguments as it did in D7.
  5. Install the Configuration Inspector module, then go to /admin/config/development/configuration/inspect and verify the configuration agrees with the schema. Fix it if it doesn't.
  6. Manually test the reaction rules for your module by performing module-specific operations that should invoke the rules and seeing if the expected action took place. The specifics of this are dependent upon your module.
  7. Write PHPUnit functional test cases for each reaction rule. These tests simulate a browser session and check to see that the expected actions occur - this is the automated equivalent of the previous step. If your Drupal 7 module already has test cases for reaction rules, then those are easily ported to D8 (need link to core Drupal document about porting test cases).

Help improve this page

Page status: No known problems

You can: