1. commerce
    1. 7
7 public DrupalCommerceEntityController::view($entities, $view_mode = '', $langcode = NULL, $page = NULL)

Generate an array for rendering the given entities.


$entities An array of entities to render.

$view_mode View mode, 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 embeded 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

The renderable array.


includes/commerce.controller.inc, line 319

public function view($entities, $view_mode = '', $langcode = NULL, $page = NULL) {
  // If no view mode is specified, use the first one available..
  if (!isset($this->entityInfo['view modes'][$view_mode])) {
    reset($this->entityInfo['view modes']);
    $view_mode = key($this->entityInfo['view modes']);

  if (!empty($this->entityInfo['fieldable'])) {
    field_attach_prepare_view($this->entityType, $entities, $view_mode);

  entity_prepare_view($this->entityType, $entities);
  $langcode = isset($langcode) ? $langcode : $GLOBALS['language_content']->language;
  $view = array();

  // Build the content array for each entity passed in.
  foreach ($entities as $key => $entity) {
    $build = entity_build_content($this->entityType, $entity, $view_mode, $langcode);

    // Add default properties to the array to ensure the content is passed
    // through the theme layer.
    $build += array(
      '#theme' => 'entity', 
      '#entity_type' => $this->entityType, 
      '#entity' => $entity, 
      '#view_mode' => $view_mode, 
      '#language' => $langcode, 
      '#page' => $page,

    // Allow modules to modify the structured entity.
    drupal_alter(array($this->entityType . '_view', 'entity_view'), $build, $this->entityType);
    $view[$this->entityType][$key] = $build;

  return $view;