Module rules provide an opportunity for web developers to carry out some actions after certain events have occurred. It has a list of events and activities in its structure, which we may make use of so as to create our own rules. There are situations, however, when the items on the list are not applicable to implementing the planned functionality. In this case, you can create your own «action» or «event».
This article is describing how the functionality for creating your own activities and events is implemented. So, first of all, you need to download and install the Rules module, which will provide us with the necessary API, and afterward, we will proceed to fulfill the set objective. You start creating your own «Action» with the announcement of hook_rules_action_info (). It is desirable, for this purpose, create a separate file module.rules.inc, ("module" is the name of your own module), in which the code is supposed to be kept. By way of illustration, we will have some messages to users with a certain role been displayed. We will need to pass into the event execution function the role of users whom the message is going to be displayed to, and the text of the message proper. Let’s start with the implementation of the Hook:
/** * Implements hook_rules_action_info(). */ function internetdevels_rules_action_info() { $actions = array( 'internetdevels_view_message' => array( 'label' => t('View message for selected users'), 'group' => t('My custom actions'), 'parameter' => array( // To select a user role. 'roles' => array( 'type' => 'list<integer>', 'label' => t('Roles'), 'options list' => 'entity_metadata_user_roles', 'description' => t('Select the roles whose users can view your message.'), ), // Messages that should appear after a particular action. 'message' => array( 'type' => 'text', 'label' => t('Message'), 'description' => t("The message body."), ), ), ), ); return $actions; }