Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By andypost on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.8.x
Description:
Following functions are deprecated and should not be used.
- entity_view()
- entity_view_multiple()
- comment_view()
- comment_view_multiple()
- node_view()
- node_view_multiple()
- taxonomy_term_view()
- taxonomy_term_view_multiple()
- user_view()
- user_view_multiple()
Instead use to inject entity view builder handler into controller and call view()
or viewMultiple()
Examples
Before
$build = entity_view($node, 'teaser')
$build = entity_view_multiple($nodes, 'teaser')
After
$builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$build = $builder->view($node, 'teaser');
$builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$build = $builder->viewMultiple($nodes, 'teaser');
Impacts:
Module developers