function _services_entity_resource_retrieve in Services Entity API 7
1 string reference to '_services_entity_resource_retrieve'
- services_entity_services_resources in ./services_entity.services.inc
- Implementation of hook_services_resources().
File
- ./services_entity.resources.inc, line 30
Code
function _services_entity_resource_retrieve($entity_type, $entity_key, $fields) {
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', $entity_type)
->addTag('service_entity_resource')
->addMetaData('entity_type', $entity_type);
if (strpos($entity_key, ':') == 0) {
$query
->entityCondition('entity_id', $entity_key);
}
else {
list($key, $value) = explode(':', $entity_key);
$info = entity_get_info($entity_type);
$schema = drupal_get_schema($info['base table']);
if (!empty($schema['unique keys'][$key])) {
$query
->propertyCondition($key, $value);
}
else {
return services_error(t('Loading an entity using a non unique property is not allowed.'), 404);
}
}
$entities = $query
->execute();
if (!empty($query->ordered_results)) {
$result = _services_postprocess_entities($entities, $query->ordered_results, $fields);
return reset($result);
}
else {
return services_error(t('No entities retrieved.'), 404);
}
}