public function EntityResource::get

Responds to entity GET requests.

Parameters

mixed $id: The entity ID.

Return value

\Drupal\rest\ResourceResponse The response containing the loaded entity.

Throws

\Symfony\Component\HttpKernel\Exception\HttpException

File

drupal/core/modules/rest/lib/Drupal/rest/Plugin/rest/resource/EntityResource.php, line 44
Definition of Drupal\rest\Plugin\rest\resource\EntityResource.

Class

EntityResource
Represents entities as resources.

Namespace

Drupal\rest\Plugin\rest\resource

Code

public function get($id) {
  $definition = $this
    ->getPluginDefinition();
  $entity = entity_load($definition['entity_type'], $id);
  if ($entity) {
    if (!$entity
      ->access('view')) {
      throw new AccessDeniedHttpException();
    }
    foreach ($entity as $field_name => $field) {
      if (!$field
        ->access('view')) {
        unset($entity->{$field_name});
      }
    }
    return new ResourceResponse($entity);
  }
  throw new NotFoundHttpException(t('Entity with ID @id not found', array(
    '@id' => $id,
  )));
}