1 entity.module entity_view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)

Generate an array for rendering the given entity.

Parameters

EntityInterface $entity: An entity object to render.

string $view_mode: A view mode as used by this entity type, e.g. 'full', 'teaser'...

string $langcode: (optional) A language code to use for rendering. Defaults to the global content language of the current request.

Return value

The renderable array. If there is no information on how to view an entity,: FALSE is returned.

File

core/modules/entity/entity.module, line 247
Entity API for handling entities like nodes or users.

Code

function entity_view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
  $entity_type = $entity->entityType();
  $info = entity_get_info($entity_type);

  if (in_array('EntityControllerInterface', class_implements($info['controller class']))) {
    $view = entity_get_controller($entity_type)->view(array($entity->id() => $entity), $view_mode, $langcode);
    return $view[$entity_type][$entity->id()];
  }

  return FALSE;
}