You are here

public function ServicesEntityResourceController::retrieve in Services Entity API 7.2

Implements ServicesResourceControllerInterface::retrieve().

Overrides ServicesResourceControllerInterface::retrieve

1 call to ServicesEntityResourceController::retrieve()
ServicesEntityResourceControllerClean::retrieve in plugins/services_entity_resource_clean.inc
Implements ServicesResourceControllerInterface::retrieve().
1 method overrides ServicesEntityResourceController::retrieve()
ServicesEntityResourceControllerClean::retrieve in plugins/services_entity_resource_clean.inc
Implements ServicesResourceControllerInterface::retrieve().

File

plugins/services_entity_resource.inc, line 62

Class

ServicesEntityResourceController
Generic controller for entity-bases resources.

Code

public function retrieve($entity_type, $entity_id, $fields, $revision) {
  if (!empty($revision)) {

    // If a specific revision is requested, then retrieve it.
    if ($entity = entity_revision_load($entity_type, $revision)) {
      list($id) = entity_extract_ids($entity_type, $entity);
      if ($id !== $entity_id) {
        services_error('Requested revision id does not match the resource id.', 406);
      }
    }
  }
  else {
    $entity = entity_load_single($entity_type, $entity_id);
  }
  if (!$entity) {
    services_error('Entity or revision not found', 404);
  }

  // Users get special treatment to remove sensitive data.
  if ($entity_type == 'user') {

    // Use the helper that Services module already has.
    services_remove_user_data($entity);
  }
  return $this
    ->limit_fields($entity, $fields);
}