public function RestfulEntityBase::viewEntity in RESTful 7
View an entity.
Parameters
$id: The ID to load the entity.
Return value
array Array with the public fields populated.
Throws
Exception
Overrides RestfulDataProviderEFQ::viewEntity
7 calls to RestfulEntityBase::viewEntity()
- RestfulAccessTokenAuthentication::getOrCreateToken in modules/
restful_token_auth/ plugins/ restful/ restful_token_auth/ token_auth/ access_token/ 1.0/ RestfulAccessTokenAuthentication.class.php - Create a token for a user, and return its value.
- RestfulEntityBase::createEntity in plugins/
restful/ RestfulEntityBase.php - Create a new entity.
- RestfulEntityBase::getList in plugins/
restful/ RestfulEntityBase.php - Get a list of entities.
- RestfulEntityBase::updateEntity in plugins/
restful/ RestfulEntityBase.php - Update an entity.
- RestfulEntityBase::viewEntities in plugins/
restful/ RestfulEntityBase.php - Get a list of entities based on a list of IDs.
File
- plugins/
restful/ RestfulEntityBase.php, line 280 - Contains RestfulEntityBase.
Class
- RestfulEntityBase
- An abstract implementation of RestfulEntityInterface.
Code
public function viewEntity($id) {
$entity_id = $this
->getEntityIdByFieldId($id);
$request = $this
->getRequest();
$cached_data = $this
->getRenderedCache($this
->getEntityCacheTags($entity_id));
if (!empty($cached_data->data)) {
return $cached_data->data;
}
if (!$this
->isValidEntity('view', $entity_id)) {
return;
}
$wrapper = entity_metadata_wrapper($this->entityType, $entity_id);
$wrapper
->language($this
->getLangCode());
$values = array();
$limit_fields = !empty($request['fields']) ? explode(',', $request['fields']) : array();
foreach ($this
->getPublicFields() as $public_field_name => $info) {
if ($limit_fields && !in_array($public_field_name, $limit_fields)) {
// Limit fields doesn't include this property.
continue;
}
$value = NULL;
if ($info['create_or_update_passthrough']) {
// The public field is a dummy one, meant only for passing data upon
// create or update.
continue;
}
if ($info['callback']) {
$value = static::executeCallback($info['callback'], array(
$wrapper,
));
}
else {
// Exposing an entity field.
$property = $info['property'];
$sub_wrapper = $info['wrapper_method_on_entity'] ? $wrapper : $wrapper->{$property};
// Check user has access to the property.
if ($property && !$this
->checkPropertyAccess('view', $public_field_name, $sub_wrapper, $wrapper)) {
continue;
}
if (empty($info['formatter'])) {
if ($sub_wrapper instanceof EntityListWrapper) {
// Multiple values.
foreach ($sub_wrapper as $item_wrapper) {
$value[] = $this
->getValueFromProperty($wrapper, $item_wrapper, $info, $public_field_name);
}
}
else {
// Single value.
$value = $this
->getValueFromProperty($wrapper, $sub_wrapper, $info, $public_field_name);
}
}
else {
// Get value from field formatter.
$value = $this
->getValueFromFieldFormatter($wrapper, $sub_wrapper, $info);
}
}
if (isset($value) && $info['process_callbacks']) {
foreach ($info['process_callbacks'] as $process_callback) {
$value = static::executeCallback($process_callback, array(
$value,
));
}
}
$values[$public_field_name] = $value;
}
$this
->setRenderedCache($values, $this
->getEntityCacheTags($entity_id));
return $values;
}