You are here

function _rules_initialize_variables in Rules 6

Processes the given variables and initializes the variables data of the state

Note that the order of the arguments will be kept, as it might be important for passing the variables to further variable loading handlers.

Parameters

$state The current evaluation state:

$args The arguments passed with the event invocation:

1 call to _rules_initialize_variables()
rules_invoke_rule_set in rules/rules.module
Invokes configured rules for the given rule set

File

rules/rules.variables.inc, line 17
Provides functions and classes for handling variables

Code

function _rules_initialize_variables(&$state, $args) {
  $argument_names = array_keys($state['set_info']['arguments']);
  if (isset($args[0]) && count($args) == 1 && is_array($args[0]) && count($args[0]) > 0 && array_diff(array_keys($args[0]), $argument_names) === array()) {

    //the caller passed an array of arguments, so let's use that
    $data = $args[0];
  }
  else {
    $data = array();
    foreach ($argument_names as $index => $name) {
      $data[$name] =& $args[$index];
    }
  }
  $state['variables'] = array();
  foreach ($state['set_info']['arguments'] as $name => $info) {
    $variable = new rules_variable();
    $data += array(
      $name => NULL,
    );
    $variable
      ->construct($state, $name, $data[$name]);
  }
}