You are here

function entity_view in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/includes/entity.inc \entity_view()

Returns the render array for an entity.

$view_builder = \Drupal::entityManager()
  ->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\EntityManagerInterface::getViewBuilder()

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

12 calls to entity_view()
BlockViewBuilderTest::testBasicRendering in core/modules/block/src/Tests/BlockViewBuilderTest.php
Tests the rendering of blocks.
comment_preview in core/modules/comment/comment.module
Generates a comment preview.
comment_view in core/modules/comment/comment.module
Generates an array for rendering a comment.
contact_mail in core/modules/contact/contact.module
Implements hook_mail().
EntityReferenceEntityFormatter::viewElements in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php
Builds a renderable array for a field value.

... See full list

8 string references to 'entity_view'
BlockContentCacheTagsTest::testBlock in core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php
Tests that the block is cached with the correct contexts and tags.
BlockViewBuilder::viewMultiple in core/modules/block/src/BlockViewBuilder.php
Builds the render array for the provided entities.
BlockViewBuilderTest::testBlockViewBuilderBuildAlter in core/modules/block/src/Tests/BlockViewBuilderTest.php
Tests block build altering.
EntityCacheTagsTestBase::testReferencedEntity in core/modules/system/src/Tests/Entity/EntityCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity when referenced.
EntityRepository::getTranslationFromContext in core/lib/Drupal/Core/Entity/EntityRepository.php
Gets the entity translation to be used in the given context.

... See full list

File

core/includes/entity.inc, line 358
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);
}