You are here

function entity_view in Entity API 7

Generate an array for rendering the given entities.

Entities being viewed, are generally expected to be fully-loaded entity objects, thus have their name or id key set. However, it is possible to view a single entity without any id, e.g. for generating a preview during creation.

Parameters

$entity_type: The type of the entity.

$entities: An array of entities to render.

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

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

$page: (optional) If set will control if the entity is rendered: if TRUE the entity will be rendered without its title, so that it can be embedded in another context. If FALSE the entity will be displayed with its title in a mode suitable for lists. If unset, the page mode will be enabled if the current path is the URI of the entity, as returned by entity_uri(). This parameter is only supported for entities which controller is a EntityAPIControllerInterface.

Return value

array The renderable array, keyed by the entity type and by entity identifiers, for which the entity name is used if existing - see entity_id(). If there is no information on how to view an entity, FALSE is returned.

5 calls to entity_view()
EntityDrupalWrapper::view in includes/entity.wrapper.inc
Returns the entity prepared for rendering.
entity_entity_view_content_type_render in ctools/content_types/entity_view.inc
Implements hook_PLUGIN_content_type_render().
entity_views_handler_area_entity::render_entity in views/handlers/entity_views_handler_area_entity.inc
Render an entity using the view mode.
entity_views_handler_field_entity::render_single_value in views/handlers/entity_views_handler_field_entity.inc
Render a single field value.
entity_views_plugin_row_entity_view::pre_render in views/plugins/entity_views_plugin_row_entity_view.inc
Allow the style to do stuff before each row is rendered.
1 string reference to 'entity_view'
EntityAPIController::view in includes/entity.controller.inc
Implements EntityAPIControllerInterface.

File

./entity.module, line 629

Code

function entity_view($entity_type, $entities, $view_mode = 'full', $langcode = NULL, $page = NULL) {
  $info = entity_get_info($entity_type);
  if (isset($info['view callback'])) {
    $entities = entity_key_array_by_property($entities, $info['entity keys']['id']);
    return $info['view callback']($entities, $view_mode, $langcode, $entity_type);
  }
  elseif (in_array('EntityAPIControllerInterface', class_implements($info['controller class']))) {
    return entity_get_controller($entity_type)
      ->view($entities, $view_mode, $langcode, $page);
  }
  return FALSE;
}