You are here

function node_view in Drupal 8

Same name and namespace in other branches
  1. 4 modules/node.module \node_view()
  2. 5 modules/node/node.module \node_view()
  3. 6 modules/node/node.module \node_view()
  4. 7 modules/node/node.module \node_view()

Generates an array for rendering the given node.

Parameters

\Drupal\node\NodeInterface $node: A node entity.

$view_mode: (optional) View mode, e.g., 'full', 'teaser', etc. Defaults to 'full.'

$langcode: (optional) A language code to use for rendering. Defaults to NULL which is the global content language of the current request.

Return value

array An array as expected by \Drupal\Core\Render\RendererInterface::render().

Deprecated

in drupal:8.7.0 and is removed from drupal:9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('node')->view() instead.

See also

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

1 call to node_view()
NodeLegacyTest::testNodeView in core/modules/node/tests/src/Kernel/NodeLegacyTest.php
@expectedDeprecation node_view() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('node')->view() instead. See…
7 string references to 'node_view'
CommentRssTest::testCommentRss in core/modules/comment/tests/src/Functional/CommentRssTest.php
Tests comments as part of an RSS feed.
FrontPageTest::doTestFrontPageViewCacheTags in core/modules/node/tests/src/Functional/Views/FrontPageTest.php
Tests the cache tags on the front page.
PageCacheTagsIntegrationTest::testPageCacheTags in core/modules/page_cache/tests/src/Functional/PageCacheTagsIntegrationTest.php
Test that cache tags are properly bubbled up to the page level.
SearchPageCacheTagsTest::testSearchTagsBubbling in core/modules/search/tests/src/Functional/SearchPageCacheTagsTest.php
Tests the presence of expected cache tags with referenced entities.
UrlTest::setUp in core/tests/Drupal/Tests/Core/UrlTest.php

... See full list

File

core/modules/node/node.module, line 867
The core module that allows content to be submitted to the site.

Code

function node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL) {
  @trigger_error("node_view() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \\Drupal::entityTypeManager()->getViewBuilder('node')->view() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED);
  return \Drupal::entityTypeManager()
    ->getViewBuilder('node')
    ->view($node, $view_mode, $langcode);
}