Porting Actions

Last updated on
11 December 2021

Tasks

  1. Make a list of actions that your module defines.
  2. Rules actions are defined by hook_rules_action_info(), which 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 these files to ensure that you port ALL the actions that were in D7.
  3. Write a <modulename>/src/Plugin/RulesAction/<actionname>.php class for each action that the module defines. Make this class extend \Drupal\rules\Core\RulesActionBase. Use the classes provided by the Rules module in rules/src/Plugin/RulesAction/* as examples.
  4. The contents of hook_rules_action_info() will mostly go into the annotation for your new class (the syntax of the annotation is different than the syntax of the hook, but the content is almost exactly the same). The callback function will go into the doExecute() method of the class, and any helper functions will become protected methods in the class.
  5. Manually test, in the Rules UI, that each action shows up and has the same arguments as it did in D7.
  6. Manually review the action plugins to make sure all comments and text strings are correct for each action.
  7. Manually test, by creating test reaction rules in the Rules UI, that each action works as expected.
  8. Write unit test cases for each action. Use the code in rules/tests/src/Unit/Integration/RulesAction/* as examples.

Try not to skip writing the tests - these are EXTREMELY useful for maintaining your module and for documenting how you expect your actions to work.

Help improve this page

Page status: No known problems

You can: