public function RestfulDataProviderVariable::mapVariableToPublicFields in RESTful 7
Maps variable names and values to public fields.
Parameters
array $variable: An array containing the name and value of the variable.
2 calls to RestfulDataProviderVariable::mapVariableToPublicFields()
- RestfulDataProviderVariable::index in plugins/
restful/ RestfulDataProviderVariable.php - Get a list of entities.
- RestfulDataProviderVariable::viewVariable in plugins/
restful/ RestfulDataProviderVariable.php - View a single variable.
File
- plugins/
restful/ RestfulDataProviderVariable.php, line 253 - Contains \RestfulDataProviderDbQuery
Class
- RestfulDataProviderVariable
- @file Contains \RestfulDataProviderDbQuery
Code
public function mapVariableToPublicFields($variable) {
foreach ($this
->getPublicFields() as $public_field_name => $info) {
if (!empty($info['property'])) {
if (isset($info['property']) && $info['property'] == 'name') {
$public_field_value = $variable['name'];
}
elseif (isset($info['property']) && $info['property'] == 'value') {
$public_field_value = $variable['value'];
}
else {
throw new RestfulBadRequestException("The only possible properties for the variable resource are 'name' and 'value'.");
}
}
elseif ($info['callback']) {
$public_field_value = static::executeCallback($info['callback'], array(
$name,
));
}
// Modify the public field value using a process callback, if supplied.
if ($public_field_value && $info['process_callbacks']) {
foreach ($info['process_callbacks'] as $process_callback) {
$public_field_value = static::executeCallback($process_callback, array(
$public_field_value,
));
}
}
$return[$public_field_name] = $public_field_value;
}
return $return;
}