entity_view

entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $reset = FALSE)

Returns the render array for an entity.

$view_builder = \Drupal::entityTypeManager()
  ->getViewBuilder($entity->getEntityTypeId());
return $view_builder->view($entity, $view_mode, $langcode);

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to be rendered.

string $view_mode: The view mode that should be used to display the entity.

string $langcode: (optional) For which language the entity should be rendered, defaults to the current content language.

bool $reset: (optional) Whether to reset the render cache for the requested entity. Defaults to FALSE.

Return value

array A render array for the entity.

Deprecated

as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Use the entity view builder's view() method for creating a render array:

See also

\Drupal\Core\Entity\EntityTypeManagerInterface::getViewBuilder()

\Drupal\Core\Entity\EntityViewBuilderInterface::view()

File

core/includes/entity.inc, line 367
Entity API for handling entities like nodes or users.

Code

function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $reset = FALSE) {
  $render_controller = \Drupal::entityManager()->getViewBuilder($entity->getEntityTypeId());
  if ($reset) {
    $render_controller->resetCache([$entity]);
  }
  return $render_controller->view($entity, $view_mode, $langcode);
}
doc_Drupal
2016-10-29 09:09:17
Comments
Leave a Comment

Please login to continue.