function rules_unwrap_data
Unwraps the given data, if it's wrapped.
Parameters
array $data: An array of wrapped data.
array $info: Optionally an array of info about how to unwrap the data. Keyed as $data.
Return value
array An array containing unwrapped or passed through data.
7 calls to rules_unwrap_data()
- RulesPHPEvaluator::evaluate in modules/
php.eval.inc - Evaluates PHP code contained in $text.
- RulesPlugin::getArgument in includes/
rules.core.inc - Returns the argument for the parameter $name described with $info.
- RulesPlugin::getExecutionArguments in includes/
rules.core.inc - Gets the right arguments for executing the element.
- RulesPlugin::returnVariables in includes/
rules.core.inc - Gets variables to return once the configuration has been executed.
- RulesState::get in includes/
rules.state.inc - Gets a variable.
File
-
./
rules.module, line 612
Code
function rules_unwrap_data(array $data, $info = array()) {
$cache = rules_get_cache();
foreach ($data as $key => $entry) {
// If it's a wrapper, unwrap unless specified otherwise.
if ($entry instanceof EntityMetadataWrapper) {
if (!isset($info[$key]['allow null'])) {
$info[$key]['allow null'] = FALSE;
}
if (!isset($info[$key]['wrapped'])) {
// By default, do not unwrap special data types that are always wrapped.
$info[$key]['wrapped'] = isset($info[$key]['type']) && is_string($info[$key]['type']) && !empty($cache['data_info'][$info[$key]['type']]['is wrapped']);
}
// Activate the decode option by default if 'sanitize' is not enabled, so
// any text is either sanitized or decoded.
// @see EntityMetadataWrapper::value()
$options = $info[$key] + array(
'decode' => empty($info[$key]['sanitize']),
);
try {
if (!($info[$key]['allow null'] && $info[$key]['wrapped'])) {
$value = $entry->value($options);
if (!$info[$key]['wrapped']) {
$data[$key] = $value;
}
if (!$info[$key]['allow null'] && !isset($value)) {
throw new RulesEvaluationException('The variable or parameter %name is empty.', array(
'%name' => $key,
));
}
}
} catch (EntityMetadataWrapperException $e) {
throw new RulesEvaluationException('Unable to get the data value for the variable or parameter %name. Error: !error', array(
'%name' => $key,
'!error' => $e->getMessage(),
));
}
}
}
return $data;
}