function entity_view

Returns the render array for an entity.

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

in drupal:8.0.0 and is removed from drupal:9.0.0. Use the entity view builder's view() method for creating a render array:

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

See also

https://www.drupal.org/node/3033656

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

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

1 call to entity_view()
EntityLegacyTest::testEntityView in core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php
@expectedDeprecation entity_view() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, $view_mode, $langcode) instead. Seeā€¦
10 string references to 'entity_view'
BlockContentCacheTagsTest::testBlock in core/modules/block_content/tests/src/Functional/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/tests/src/Kernel/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.
EntityCacheTagsTestBase::testReferencedEntity in core/modules/system/tests/src/Functional/Entity/EntityCacheTagsTestBase.php
Tests cache tags presence and invalidation of the entity when referenced.

... See full list

File

core/includes/entity.inc, line 341

Code

function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $reset = FALSE) {
    @trigger_error('entity_view() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \\Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->view($entity, $view_mode, $langcode) instead. See https://www.drupal.org/node/3033656', E_USER_DEPRECATED);
    $render_controller = \Drupal::entityManager()->getViewBuilder($entity->getEntityTypeId());
    if ($reset) {
        $render_controller->resetCache([
            $entity,
        ]);
    }
    return $render_controller->view($entity, $view_mode, $langcode);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.