On this page
Porting Actions
Last updated on
11 December 2021
Tasks
- Make a list of actions that your module defines.
- 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>.moduleinstead). Refer to the D7 version of these files to ensure that you port ALL the actions that were in D7. - Write a
<modulename>/src/Plugin/RulesAction/<actionname>.phpclass for each action that the module defines. Make this class extend\Drupal\rules\Core\RulesActionBase. Use the classes provided by the Rules module inrules/src/Plugin/RulesAction/*as examples. - 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 thedoExecute()method of the class, and any helper functions will become protected methods in the class. - Manually test, in the Rules UI, that each action shows up and has the same arguments as it did in D7.
- Manually review the action plugins to make sure all comments and text strings are correct for each action.
- Manually test, by creating test reaction rules in the Rules UI, that each action works as expected.
- 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:
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