protected function RestWSBaseFormat::getResourceReferenceValue in RESTful Web Services 7.2
Gets the resource reference value.
Parameters
$type: The data type of the reference property.
array $reference: The input data specifying the resource reference in one supported way.
Return value
mixed The value to be set for the reference. Usually this is an entity or resource id, but for generic entity references it's an EntityDrupalWrapper.
See also
RestWSBaseFormat::getResourceReference()
2 calls to RestWSBaseFormat::getResourceReferenceValue()
- RestWSBaseFormat::getPropertyValues in ./
restws.formats.inc - Transforms simple-array data values to valid entity property values.
- RestWSFormatXML::xmlToArray in ./
restws.formats.inc - Turns the xml structure into an array of values.
File
- ./
restws.formats.inc, line 311 - RESTful web services module formats.
Class
- RestWSBaseFormat
- A base for all simple formats that are just serializing/unserializing an array of property values.
Code
protected function getResourceReferenceValue($type, array $reference) {
if (isset($reference['id']) && $type != 'entity') {
return $reference['id'];
}
elseif ($type == 'entity' && isset($reference['id']) && isset($reference['resource'])) {
if (!entity_get_info($reference['resource'])) {
throw new RestWSException('Invalid resource for entity reference given.', 406);
}
return entity_metadata_wrapper($reference['resource'], $reference['id']);
}
elseif (isset($reference['uri'])) {
// @todo: Implement setting references by URI by parsing resource/id from
// the URI.
}
elseif (isset($reference['uuid']) && module_exists('uuid') && $type != 'entity') {
$ids = entity_get_id_by_uuid($type, array(
$reference['uuid'],
));
if (!$ids) {
throw new RestWSException('Invalid UUID for resource reference given.', 406);
}
return reset($ids);
}
throw new RestWSException('Invalid value for resource reference given.', 406);
}