You are here

public function MerciDefaultEntityController::view in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

Generate an array for rendering the given entities.

Parameters

$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.

Overrides EntityAPIControllerInterface::view

File

merci_line_item/includes/merci_line_item.controller.inc, line 375
Provides a central controller for Drupal Commerce.

Class

MerciDefaultEntityController
@file Provides a central controller for Drupal Commerce.

Code

public function view($entities, $view_mode = '', $langcode = NULL, $page = NULL) {

  // Create a new entities array keyed by entity ID.
  $rekeyed_entities = array();
  foreach ($entities as $key => $entity) {

    // Use the entity's ID if available and fallback to its existing key value
    // if we couldn't determine it.
    if (isset($entity->{$this->idKey})) {
      $key = $entity->{$this->idKey};
    }
    $rekeyed_entities[$key] = $entity;
  }
  $entities = $rekeyed_entities;

  // 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;
}