You are here

protected function ServicesEntityResourceController::limit_fields in Services Entity API 7.2

Limit the fields in an entity to the list provided.

Parameters

$entity: The entity to limit the fields of.

$fields: A list of field names. '*' is a wildcard, and leaves the entity unchanged.

Return value

The entity with any property not specified in $fields removed from it.

3 calls to ServicesEntityResourceController::limit_fields()
ServicesEntityResourceController::field in plugins/services_entity_resource.inc
Implements ServicesResourceControllerInterface::field().
ServicesEntityResourceController::index in plugins/services_entity_resource.inc
Implements ServicesResourceControllerInterface::index().
ServicesEntityResourceController::retrieve in plugins/services_entity_resource.inc
Implements ServicesResourceControllerInterface::retrieve().

File

plugins/services_entity_resource.inc, line 208

Class

ServicesEntityResourceController
Generic controller for entity-bases resources.

Code

protected function limit_fields($entity, $fields) {
  if ($fields == '*') {
    return $entity;
  }
  $field_array = explode(',', $fields);
  foreach ($entity as $field => $value) {
    if (!in_array($field, $field_array)) {
      unset($entity->{$field});
    }
  }
  return $entity;
}