2

I can't get my new Rules' condition to work.

I wrote the (simple) code below in includes/MYMODULE.rules.inc, and nothing appears in the condition list.

/**
 * Implementation of hook_rules_condition_info().
 */
function MYMODULE_rules_condition_info() {
    return array(
        'MYMODULE_rules_condition_MYCONDITION' => array(
            'label' => t('My label'),
            'group' => 'My very own group',
        )
    );
}

/**
 * Condition
 */
function MYMODULE_rules_condition_MYCONDITION() {
    // logic
    return TRUE;
}

I have already tried to flush the Drupal cache (as it seems to me that Rules uses a cache system).

2 Answers 2

1

Read Rules 2.x / Drupal 7; I think you can find what you want, there.

3
  • Thanks nourcy, but that's was my starting point. :-(
    – druvik
    Dec 23, 2011 at 11:07
  • 1
    Update Drupal install. Get back my condition code to the main .module file. Submit modules page again. That's seems to work. (I don't know if i have to be happy or not)
    – druvik
    Dec 23, 2011 at 11:15
  • 1
    If your code works in the main module, but not in your custom module then is you custom module installed correctly? Is it enabled? Does the module do anything else that is working correctly?
    – Ashlar
    Dec 23, 2011 at 16:11
1

Custom Rules condition:

/**
 * Implements of hook_rules_condition_info().
 */
function your_module_rules_condition_info() {
  return array(
    'your_module_condition_package_type' => array(
      'label' => t('Type of the package'),
      'arguments' => array(
        'package_id' => array('type' => 'value', 'label' => t('The type of the purchased package.')),
        'package_type' => array('type' => 'string', 'label' => t('The type of the purchased package is')),
      ),
      'module' => 'your_module',
      'group' => 'My very own group',
    ),
  );
}
/**
 * Condition packages_condition_packagetype
 */
function your_module_condition_package_type($pid, $type) {
  $package = package_load($pid);
  return ($package->type == $type) ? true : false;
}

See more in Rules examples

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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