5

I am trying to add custom actions, events and conditions to work with Rules interface. I began by adding custom actions by creating a custom module. Here's my code till now.

rules_example.info :

name = Rules Example
description = Test module to add new actions, events, and conditions
core = 7.x

rules_example.module :

<?php
/**
 */

rules_example.rules.inc :

<?php

 /**
  * @file
  * Example rules module to create actions, events, and conditions
  */

/**
 * Implement hook_rules_action_info()

 * Declare any meta data about actions for Rules
 */

function rules_example_rules_action_info() {
$actions = array(
    'rules_example_actions_hello_world' => array(
        'label' => t('Print Hello World on the page'),
        'group' => t('Rules Example'),
        ),
    'rules_example_actions_hello_user' => array(
        'label' => t('Print Hello to the logged in user'),
        'group' => t('Rules Example'),
        'parameter' => array(
            'account' => array(
                'type' => 'user',
                'label' => t('User to say hello to'),
                ),
            ),
        ),
    );

return $actions;
}

/**
 * The action function for rules_example_action_hello_world
 */

function rules_example_action_hello_world() {
drupal_set_message(t('Hello World'));
} 

/** 
 * The action function for rules_example_action_hello_user
 */

function rules_example_action_hello_user($account) {
drupal_set_message(t('Hello @username',
 array('@username' => $account->name)));
}

Well, this is it. I have saved all these files in a folder rules_example in sites/all/modules. When i install the module or rather try to install it i get this error:

ReflectionException: Function rules_example_actions_hello_world() does not exist in ReflectionFunction->__construct() (line 1691 of /opt/lampp/htdocs/sites/all/modules/rules/includes/rules.core.inc)

I am not sure what the error is. I am going to rules.core.inc but am not able to understand what is causing the error. Thanks.

  • shouldn't you have files[] = my_module.rules.inc in your info file? – hkoosha Jul 4 '13 at 13:54
  • 1
    @loolooyyyy I don't think files[] is for generally including code - it's for classes and interfaces specifically. – Joe Beuckman Aug 27 '13 at 14:34
9

There is a typo in your code - the function name is "rules_example_actions_hello_world" in your actions definition, while the actual function is called "rules_example_action_hello_world".

1

In rules_example.module, add this:

module_load_include('inc', 'rules_example', 'rules_example.rules');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.