Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
after digging through rules source for a while I decided to ask.
I want to execute a rule programmatically by knowing its machine name. I'm aware of the fact, that it would be much more simple a task to create a component and invoke that, or issue the according event. But neither is what I want to do.
What I've been trying so long:
// Load the rule(s).
$rules = rules_config_load_multiple(array('my_rule'));
// Try to run the rule(s).
foreach ($rules as $rule) {
$state = new RulesState();
$rule->evaluate($state);
}
Though I can tell it does something, it does not really evaluate the rule ;-).
Any help or hint is appreciate.
Comments
Comment #1
attisancould the following snippet be the way to go?
Comment #2
TR CreditAttribution: TR commentedWhen in doubt, first look at the Simpletest cases to see how to programmatically create and invoke rules.
Here's how the test runs a rule that has a "node" parameter as input: