You are here

public function CaseTrackerProjectController::view in Case Tracker 7.2

Implements EntityAPIControllerInterface.

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, keyed by entity name or numeric id.

Overrides EntityAPIController::view

File

includes/controller/CaseTrackerProjectController.inc, line 61

Class

CaseTrackerProjectController
The Controller for CaseTrackerProject entities

Code

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

  // For Field API and entity_prepare_view, the entities have to be keyed by
  // (numeric) id.
  $entities = entity_key_array_by_property($entities, $this->idKey);
  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();
  $CaseTrackerCaseController = new CaseTrackerCaseController();
  foreach ($entities as $CaseTrackerProject) {
    $build = array();
    switch ($view_mode) {
      case 'full':
        $build['view_mode_full'] = array(
          '#theme' => 'casetracker_project_full_view_mode',
          '#CaseTrackerProject' => $CaseTrackerProject,
        );
        break;
      case 'teaser':
        $project = array(
          'id' => $CaseTrackerProject->pid,
          'created' => $CaseTrackerProject->created,
          'author' => theme('username', array(
            'account' => user_load($CaseTrackerProject->uid),
          )),
          'title' => l($CaseTrackerProject->title, 'project/' . $CaseTrackerProject->pid),
          'case_totals' => array(
            'priority' => $CaseTrackerCaseController
              ->getTotalAmountByPriority($CaseTrackerProject->pid),
            'bundle' => $CaseTrackerCaseController
              ->getTotalAmountByBundle($CaseTrackerProject->pid),
          ),
        );
        $build['view_mode_teaser'] = array(
          '#theme' => 'casetracker_project_list_view_mode',
          '#project' => $project,
        );
        break;
    }
    $build[] = entity_build_content($this->entityType, $CaseTrackerProject, $view_mode, $langcode);

    //Allow modules to modify the structured entity.
    drupal_alter(array(
      $this->entityType . '_view',
      'entity_view',
    ), $build, $this->entityType);
    $key = isset($CaseTrackerProject->{$this->idKey}) ? $CaseTrackerProject->{$this->idKey} : NULL;
    $view[$this->entityType][$key] = $build;
  }
  return $view;
}