1 entity.controller.inc public DefaultEntityController::buildContent(EntityInterface $entity, $view_mode = 'full', $langcode = NULL)

Implements EntityControllerInterface::buildContent().

Overrides EntityControllerInterface::buildContent

File

core/modules/entity/entity.controller.inc, line 579
Entity API controller classes and interface.

Class

DefaultEntityController
Defines a base entity controller class.

Code

public function buildContent(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
  global $language_content;
  $langcode = $langcode ? $langcode : $language_content->langcode;

  // Remove previously built content, if exists.
  $entity->content = array();

  // Allow modules to change the display mode.
  $view_mode = key(entity_view_mode_prepare($entity->entityType(), array($entity->id() => $entity), $view_mode, $langcode));

  // Make sure the used view-mode gets stored.
  $entity->content += array('#view_mode' => $view_mode);

  // Add in fields.
  if (!empty($this->entityInfo['fieldable'])) {
    // Perform the preparation tasks if they have not been performed yet.
    // An internal flag prevents the operation from running twice.
    $key = isset($entity->{$this->idKey}) ? $entity->{$this->idKey} : NULL;
    field_attach_prepare_view($this->entityType, array($key => $entity), $view_mode);
    $entity->content += field_attach_view($this->entityType, $entity, $view_mode, $langcode);
  }
  // Invoke hook_ENTITY_view() to allow modules to add their additions.
  module_invoke_all($this->entityType . '_view', $entity, $view_mode, $langcode);

  module_invoke_all('entity_view', $entity, $this->entityType, $view_mode, $langcode);

  return $entity->content;
}