On this page
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
- Make a list of Rules Components that your module generates. These may be found at
/admin/config/workflow/rules/componentson your Drupal 7 site. - Rules Components are defined in D7 in
hook_default_rules_configuration()and altered inhook_default_rules_configuration_alter(), or by creating an instance ofrules_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>.moduleinstead). Refer to the D7 version of this file to ensure that you port ALL the events that were in D7. - Create configuration files for these components in D8. Configuration files should go into
<modulename>/config/optional/and be namedrules.component.<rule machine name>.ymlYou 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/configurationand export the configuration file for the rule you just made. - Manually test, in the Rules UI, that each rules component shows up and has the same arguments as it did in D7.
- Install the contributed Configuration Inspector module then go to
/admin/config/development/configuration/inspectand verify the configuration agrees with the schema. Fix it if it doesn't. - Manually test the rules components by performing your module's operations that should invoke these components and seeing if the expected action took place.
- 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:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion