Hi,
I am trying to create a complex workflow with rules but I am facing an annoying issue. I try to create some component rules which can be fired by some reaction rules or by other component rules. The problem is that Components defined in the hook_default_rules_configuration function cannot be used in Components or Rules defined in this same hook, even if it is done in another module.
I made a little sample to illustrate this issue :
/**
* Implements hook_default_rules_configuration().
*/
function test_default_rules_configuration() {
$rules = array();
$rule = rule(array());
$rule->label = 'Rule Test';
$rule->active = TRUE;
$rule->action('drupal_message', array(
'message' => 'test',
));
$rules['test_rule'] = $rule;
$rule = rules_reaction_rule();
$rule->label = 'Réaction rule Test';
$rule->active = TRUE;
$rule->event('init')
->action('test_rule', array());
$rules['test_reaction_rule'] = $rule;
return $rules;
}
Attached screenshots show the result of this piece of code.
I cleared cache thrice, tried with all in the same module as above or in two different modules, well sorted using their weight.
I also tried to use hook_default_rules_configuration_alter to add actions after the Components creation and the save method of the Rule object.
The result is always the same : "Error : unknown action XXX"
What is particularly strange is that these components are aviable and working well with the UI.
Am I doing something wrong ?
Regards.
| Comment | File | Size | Author |
|---|---|---|---|
| rules.png | 6.61 KB | duaelfr | |
| components.png | 3.89 KB | duaelfr |
Comments
Comment #1
duaelfrAfter digging a lot I found that rules were adding a "component_" prefix to component names.
So the working code is
I hope it could help someone
Comment #2
mitchell commentedHi, I'm from the Rules Documentation Team, helping with an initiative to improve the completeness and consistency of Rules' documentation handbook.
This issue contains valuable information missing from the Rules handbook. The Default rules page, might be a good match for recording this.
(the formatting style is just me messing around, trying to start a new workflow of moving issues like these into the right direction)
Comment #3
duaelfrHi mitchell. Happy to read you.
Feel free to use my code samples if you think it can help anyone.
You can consider all my contributions to this issue and more generally in d.o as being released in the public domain :)
Comment #4
tr commentedI have used hook_default_rules_configuration() to define rules components.
I have used hook_default_rules_configuration() to define reaction rules.
I have used hook_default_rules_configuration() to define BOTH rules components AND reaction rules in the same hook.
I have NOT tried to define a component then use it in a reaction rule in the same hook. But it is my experience that Rules does not ever rename the components or reaction rules that I define - they always show up in the Rules UI with the same machine_id as the array key I defined in hook_default_rules_configuration().
Regardless, if you can document otherwise, please edit the Rule documentation (link above) to reflect your knowledge. It does no good to wait for others to fix things when anyone has the ability to correct the documentation.
Comment #5
tr commented