Porting Rules Components

Last updated on
11 December 2021

Rules Components are reusable, stand-alone pre-configured sets of Rules conditions and actions that can be used by Rules and other modules on your site. Components are for example useful if you want to use the same conditions, actions or rules in multiple places, or call them from your custom module.

These are the steps in the process:

Tasks

  1. Make a list of Rules Components that your module generates. These may be found at /admin/config/workflow/rules/components on your Drupal 7 site.
  2. Rules Components are defined in D7 in hook_default_rules_configuration() and altered in hook_default_rules_configuration_alter(), or by creating an instance of rules_reaction_rule() and programmatically adding pre-existing conditions, and/or actions to it. These hooks 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 components in D8. Configuration files should go into <modulename>/config/optional/ and be named rules.component.<rule machine name>.yml You can do this by using the Rules UI in D8 to recreate the rules components you see in D7, then go to /admin/config/development/configuration and export the configuration file for the rule you just made.
  4. Manually test, in the Rules UI, that each rules component shows up and has the same arguments as it did in D7.
  5. Install the contributed 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 rules components by performing your module's operations that should invoke these components and seeing if the expected action took place.
  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: