Skip to main content
5 of 5
added 6 characters in body
Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182

Here is what's needed to integrate your exported Rules component in a custom module:

<?php
function MY_MODULE_NAME_default_rules_configuration() {
  $configs = array();
  $rule = '{ "my_exported_rule" : {
    "LABEL" : "My Exported Rule",
    ...,
  }
}';
  $configs['my_exported_rule'] = rules_import($rule);
  return $configs;
}
?>

So to use such exported Rule, you need to run it through the function rules_import(). This will change the exported Rule in a format that is usable for the Rules module.

To reuse this example:

  • Replace MY_MODULE_NAME with the machine name of your module.
  • Replace the value used for $rule by the content of your exported rule.
  • Make sure to use the machine name of your rule (= my_exported_rule in my sample) as the key in $configs.

In the sample contained in the question, the machine name of the rule is rules_faircent_rules, though that is NOT what is used in the $configs ... Therefor I think you should correct your code like so:

$configs['rules_faircent_rules'] = rules_import($rule);
echo '<pre>';
print_r($configs['rules_faircent_rules'] );

Refer to the articled "Drupal 7 - Defining rules within a module using PHP" for some more details.

Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182