diff --git a/core/includes/entity.inc b/core/includes/entity.inc
index 0dc4426014..6e1f77a6dc 100644
--- a/core/includes/entity.inc
+++ b/core/includes/entity.inc
@@ -352,10 +352,12 @@ function entity_page_label(EntityInterface $entity, $langcode = NULL) {
* return $view_builder->view($entity, $view_mode, $langcode);
* @endcode
*
+ * @see https://www.drupal.org/node/3033656
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getViewBuilder()
* @see \Drupal\Core\Entity\EntityViewBuilderInterface::view()
*/
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]);
@@ -390,10 +392,12 @@ function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $res
* return $view_builder->viewMultiple($entities, $view_mode, $langcode);
* @endcode
*
+ * @see https://www.drupal.org/node/3033656
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getViewBuilder()
* @see \Drupal\Core\Entity\EntityViewBuilderInterface::viewMultiple()
*/
function entity_view_multiple(array $entities, $view_mode, $langcode = NULL, $reset = FALSE) {
+ @trigger_error('entity_view_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->viewMultiple($entities, $view_mode, $langcode) instead. See https://www.drupal.org/node/3033656', E_USER_DEPRECATED);
$render_controller = \Drupal::entityManager()->getViewBuilder(reset($entities)->getEntityTypeId());
if ($reset) {
$render_controller->resetCache($entities);
diff --git a/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php b/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php
index 71c4f55b8d..95a444dede 100644
--- a/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php
+++ b/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php
@@ -83,7 +83,8 @@ public function testBasicRendering() {
// Test the rendering of a block.
$entity = Block::load('test_block1');
- $output = entity_view($entity, 'block');
+ $builder = \Drupal::entityTypeManager()->getViewBuilder('block');
+ $output = $builder->view($entity, 'block');
$expected = [];
$expected[] = '
';
$expected[] = ' ';
@@ -107,7 +108,7 @@ public function testBasicRendering() {
],
]);
$entity->save();
- $output = entity_view($entity, 'block');
+ $output = $builder->view($entity, 'block');
$expected = [];
$expected[] = '
';
$expected[] = ' ';
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 8a63a7eae3..b4fe9931b8 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -272,10 +272,15 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie
* An array as expected by \Drupal\Core\Render\RendererInterface::render().
*
* @deprecated in Drupal 8.x and will be removed before Drupal 9.0.
- * Use \Drupal::entityManager()->getViewBuilder('comment')->view().
+ * Use \Drupal::entityTypeManager()->getViewBuilder('comment')->view().
+ *
+ * @see https://www.drupal.org/node/3033656
*/
function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode = NULL) {
- return entity_view($comment, $view_mode, $langcode);
+ @trigger_error("comment_view() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('comment')->view() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED);
+ return \Drupal::entityTypeManager()
+ ->getViewBuilder('comment')
+ ->view($comment, $view_mode, $langcode);
}
/**
@@ -296,12 +301,16 @@ function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode
* \Drupal\Core\Render\RendererInterface::render().
*
* @deprecated in Drupal 8.x and will be removed before Drupal 9.0.
- * Use \Drupal::entityManager()->getViewBuilder('comment')->viewMultiple().
+ * Use \Drupal::entityTypeManager()->getViewBuilder('comment')->viewMultiple().
*
+ * @see https://www.drupal.org/node/3033656
* @see \Drupal\Core\Render\RendererInterface::render()
*/
function comment_view_multiple($comments, $view_mode = 'full', $langcode = NULL) {
- return entity_view_multiple($comments, $view_mode, $langcode);
+ @trigger_error("comment_view_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('comment')->viewMultiple() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED);
+ return \Drupal::entityTypeManager()
+ ->getViewBuilder('comment')
+ ->viewMultiple($comments, $view_mode, $langcode);
}
/**
@@ -594,7 +603,9 @@ function comment_preview(CommentInterface $comment, FormStateInterface $form_sta
$field_name = $comment->getFieldName();
$entity = clone $entity;
$entity->$field_name->status = CommentItemInterface::HIDDEN;
- $build = entity_view($entity, 'full');
+ $build = \Drupal::entityTypeManager()
+ ->getViewBuilder($entity->getEntityTypeId())
+ ->view($entity, 'full');
}
$preview_build['comment_output_below'] = $build;
@@ -652,7 +663,9 @@ function template_preprocess_comment(&$variables) {
if (theme_get_setting('features.comment_user_picture')) {
// To change user picture settings (for instance, image style), edit the
// 'compact' view mode on the User entity.
- $variables['user_picture'] = user_view($account, 'compact');
+ $variables['user_picture'] = \Drupal::entityTypeManager()
+ ->getViewBuilder('user')
+ ->view($account, 'compact');
}
else {
$variables['user_picture'] = [];
diff --git a/core/modules/comment/src/Plugin/views/field/EntityLink.php b/core/modules/comment/src/Plugin/views/field/EntityLink.php
index a2c6911942..9760057103 100644
--- a/core/modules/comment/src/Plugin/views/field/EntityLink.php
+++ b/core/modules/comment/src/Plugin/views/field/EntityLink.php
@@ -16,7 +16,7 @@
class EntityLink extends FieldPluginBase {
/**
- * Stores the result of node_view_multiple for all rows to reuse it later.
+ * Stores the result of parent entities build for all rows to reuse it later.
*
* @var array
*/
@@ -61,7 +61,11 @@ public function preRender(&$values) {
$entities[$entity->id()] = $entity;
}
if ($entities) {
- $this->build = entity_view_multiple($entities, $this->options['teaser'] ? 'teaser' : 'full');
+ $entityTypeId = reset($entities)->getEntityTypeId();
+ $viewMode = $this->options['teaser'] ? 'teaser' : 'full';
+ $this->build = \Drupal::entityTypeManager()
+ ->getViewBuilder($entityTypeId)
+ ->viewMultiple($entities, $viewMode);
}
}
diff --git a/core/modules/comment/tests/src/Kernel/CommentLegacyTest.php b/core/modules/comment/tests/src/Kernel/CommentLegacyTest.php
new file mode 100644
index 0000000000..793ba9ae35
--- /dev/null
+++ b/core/modules/comment/tests/src/Kernel/CommentLegacyTest.php
@@ -0,0 +1,93 @@
+installEntitySchema('comment');
+ $this->installSchema('comment', ['comment_entity_statistics']);
+ CommentType::create([
+ 'id' => 'comment',
+ 'label' => $this->randomString(),
+ 'target_entity_type_id' => 'entity_test',
+ ])->save();
+ FieldStorageConfig::create([
+ 'entity_type' => 'entity_test',
+ 'type' => 'comment',
+ 'field_name' => 'comments',
+ 'settings' => [
+ 'comment_type' => 'comment',
+ ],
+ ])->save();
+ FieldConfig::create([
+ 'entity_type' => 'entity_test',
+ 'bundle' => 'entity_test',
+ 'field_name' => 'comments',
+ ])->save();
+ $this->entity = EntityTest::create(['name' => $this->randomString()]);
+ $this->entity->save();
+ }
+
+ /**
+ * Constructs comment entity.
+ *
+ * @return \Drupal\comment\CommentInterface
+ * Created comment entity.
+ */
+ protected function createComment() {
+ return Comment::create([
+ 'entity_type' => 'entity_test',
+ 'field_name' => 'comments',
+ 'entity_id' => $this->entity->id(),
+ 'comment_type' => 'comment',
+ ]);
+ }
+
+ /**
+ * @expectedDeprecation comment_view() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('comment')->view() instead. See https://www.drupal.org/node/3033656
+ * @expectedDeprecation comment_view_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('comment')->viewMultiple() instead. See https://www.drupal.org/node/3033656
+ */
+ public function testCommentView() {
+ $entity = $this->createComment();
+ $this->assertNotEmpty(comment_view($entity));
+ $entities = [
+ $this->createComment(),
+ $this->createComment(),
+ ];
+ $this->assertEquals(4, count(comment_view_multiple($entities)));
+ }
+
+}
diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module
index 2115fc76f6..2e94ee8488 100644
--- a/core/modules/contact/contact.module
+++ b/core/modules/contact/contact.module
@@ -140,7 +140,9 @@ function contact_mail($key, &$message, $params) {
case 'page_copy':
$message['subject'] .= t('[@form] @subject', $variables, $options);
$message['body'][] = t("@sender-name (@sender-url) sent a message using the contact form at @form-url.", $variables, $options);
- $build = entity_view($contact_message, 'mail');
+ $build = \Drupal::entityTypeManager()
+ ->getViewBuilder('contact_message')
+ ->view($contact_message, 'mail');
$message['body'][] = \Drupal::service('renderer')->renderPlain($build);
break;
@@ -159,7 +161,9 @@ function contact_mail($key, &$message, $params) {
$message['body'][] = t('Hello @recipient-name,', $variables, $options);
$message['body'][] = t("@sender-name (@sender-url) has sent you a message via your contact form at @site-name.", $variables, $options);
$message['body'][] = t("If you don't want to receive such emails, you can change your settings at @recipient-edit-url.", $variables, $options);
- $build = entity_view($contact_message, 'mail');
+ $build = \Drupal::entityTypeManager()
+ ->getViewBuilder('contact_message')
+ ->view($contact_message, 'mail');
$message['body'][] = \Drupal::service('renderer')->renderPlain($build);
break;
}
diff --git a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php
index e7558803ed..6047eac084 100644
--- a/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php
+++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php
@@ -156,7 +156,9 @@ public function testAccess() {
->save();
// Invoke entity view.
- entity_view($referencing_entity, 'default');
+ \Drupal::entityTypeManager()
+ ->getViewBuilder($referencing_entity->getEntityTypeId())
+ ->view($referencing_entity, 'default');
// Verify the un-accessible item still exists.
$this->assertEqual($referencing_entity->{$field_name}->target_id, $this->referencedEntity->id(), format_string('The un-accessible item still exists after @name formatter was executed.', ['@name' => $name]));
diff --git a/core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php b/core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php
index 2cdcf14841..6113f0ffcd 100644
--- a/core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php
+++ b/core/modules/field_ui/tests/src/Functional/ManageDisplayTest.php
@@ -242,7 +242,9 @@ public function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $tex
// Render a cloned node, so that we do not alter the original.
$clone = clone $node;
- $element = node_view($clone, $view_mode);
+ $element = \Drupal::entityTypeManager()
+ ->getViewBuilder('node')
+ ->view($clone, $view_mode);
$output = (string) \Drupal::service('renderer')->renderRoot($element);
$this->verbose(t('Rendered node - view mode: @view_mode', ['@view_mode' => $view_mode]) . '
' . $output);
diff --git a/core/modules/file/tests/src/Kernel/FileItemTest.php b/core/modules/file/tests/src/Kernel/FileItemTest.php
index bc6eb5457f..72f0bbfd36 100644
--- a/core/modules/file/tests/src/Kernel/FileItemTest.php
+++ b/core/modules/file/tests/src/Kernel/FileItemTest.php
@@ -141,7 +141,9 @@ public function testFileItem() {
$entity = EntityTest::create();
$entity->file_test = ['entity' => $file3];
$uri = $file3->getFileUri();
- $output = entity_view($entity, 'default');
+ $output = \Drupal::entityTypeManager()
+ ->getViewBuilder('entity_test')
+ ->view($entity, 'default');
\Drupal::service('renderer')->renderRoot($output);
$this->assertTrue(!empty($entity->file_test->entity));
$this->assertEqual($entity->file_test->entity->getFileUri(), $uri);
diff --git a/core/modules/node/node.module b/core/modules/node/node.module
index 58f79f7ec4..637e2082ff 100644
--- a/core/modules/node/node.module
+++ b/core/modules/node/node.module
@@ -678,7 +678,9 @@ function template_preprocess_node(&$variables) {
// 'compact' view mode on the User entity. Note that the 'compact'
// view mode might not be configured, so remember to always check the
// theme setting first.
- $variables['author_picture'] = user_view($node->getOwner(), 'compact');
+ $variables['author_picture'] = \Drupal::entityTypeManager()
+ ->getViewBuilder('user')
+ ->view($node->getOwner(), 'compact');
}
}
}
@@ -850,9 +852,17 @@ function node_get_recent($number = 10) {
*
* @return array
* An array as expected by \Drupal\Core\Render\RendererInterface::render().
+ *
+ * @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
*/
function node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL) {
- return entity_view($node, $view_mode, $langcode);
+ @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);
}
/**
@@ -869,9 +879,18 @@ function node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL) {
* @return array
* An array in the format expected by
* \Drupal\Core\Render\RendererInterface::render().
+ *
+ * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use
+ * \Drupal::entityTypeManager()->getViewBuilder('node')->viewMultiple()
+ * instead.
+ *
+ * @see https://www.drupal.org/node/3033656
*/
function node_view_multiple($nodes, $view_mode = 'teaser', $langcode = NULL) {
- return entity_view_multiple($nodes, $view_mode, $langcode);
+ @trigger_error("node_view_multiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('node')->viewMultiple() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED);
+ return \Drupal::entityTypeManager()
+ ->getViewBuilder('node')
+ ->viewMultiple($nodes, $view_mode, $langcode);
}
/**
diff --git a/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php b/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php
index 91b60c204a..94abf8b634 100644
--- a/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php
+++ b/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php
@@ -22,9 +22,12 @@ class UnpublishByKeywordNode extends ConfigurableActionBase {
* {@inheritdoc}
*/
public function execute($node = NULL) {
+ $elements = \Drupal::entityTypeManager()
+ ->getViewBuilder('node')
+ ->view(clone $node);
+ $render = \Drupal::service('renderer')->render($elements);
foreach ($this->configuration['keywords'] as $keyword) {
- $elements = node_view(clone $node);
- if (strpos(\Drupal::service('renderer')->render($elements), $keyword) !== FALSE || strpos($node->label(), $keyword) !== FALSE) {
+ if (strpos($render, $keyword) !== FALSE || strpos($node->label(), $keyword) !== FALSE) {
$node->setUnpublished();
$node->save();
break;
diff --git a/core/modules/node/src/Plugin/views/row/Rss.php b/core/modules/node/src/Plugin/views/row/Rss.php
index 59a1df012b..bd1e779023 100644
--- a/core/modules/node/src/Plugin/views/row/Rss.php
+++ b/core/modules/node/src/Plugin/views/row/Rss.php
@@ -126,7 +126,9 @@ public function render($row) {
$build_mode = $display_mode;
- $build = node_view($node, $build_mode);
+ $build = \Drupal::entityTypeManager()
+ ->getViewBuilder('node')
+ ->view($node, $build_mode);
unset($build['#theme']);
if (!empty($node->rss_namespaces)) {
diff --git a/core/modules/node/tests/src/Kernel/NodeLegacyTest.php b/core/modules/node/tests/src/Kernel/NodeLegacyTest.php
index fe25f457e0..d8895ff6e5 100644
--- a/core/modules/node/tests/src/Kernel/NodeLegacyTest.php
+++ b/core/modules/node/tests/src/Kernel/NodeLegacyTest.php
@@ -63,4 +63,18 @@ public function testEntityLegacyCode() {
$this->assertInstanceOf(NodeTypeInterface::class, node_type_load('page'));
}
+ /**
+ * @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 https://www.drupal.org/node/3033656
+ * @expectedDeprecation node_view_multiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('node')->viewMultiple() instead. See https://www.drupal.org/node/3033656
+ */
+ public function testNodeView() {
+ $entity = Node::create(['type' => 'page']);
+ $this->assertNotEmpty(node_view($entity));
+ $entities = [
+ Node::create(['type' => 'page']),
+ Node::create(['type' => 'page']),
+ ];
+ $this->assertEquals(4, count(node_view_multiple($entities)));
+ }
+
}
diff --git a/core/modules/rdf/tests/src/Functional/EntityReferenceFieldAttributesTest.php b/core/modules/rdf/tests/src/Functional/EntityReferenceFieldAttributesTest.php
index 9ef3252fe6..95c9fa884f 100644
--- a/core/modules/rdf/tests/src/Functional/EntityReferenceFieldAttributesTest.php
+++ b/core/modules/rdf/tests/src/Functional/EntityReferenceFieldAttributesTest.php
@@ -97,7 +97,9 @@ public function testNodeTeaser() {
]);
// Render the node.
- $node_render_array = entity_view_multiple([$node], 'teaser');
+ $node_render_array = \Drupal::entityTypeManager()
+ ->getViewBuilder('node')
+ ->view($node, 'teaser');
$html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parse the teaser.
diff --git a/core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php b/core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php
index 39931cd0d1..8270fe820e 100644
--- a/core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php
+++ b/core/modules/rdf/tests/src/Functional/FileFieldAttributesTest.php
@@ -75,7 +75,9 @@ protected function setUp() {
*/
public function testNodeTeaser() {
// Render the teaser.
- $node_render_array = entity_view_multiple([$this->node], 'teaser');
+ $node_render_array = \Drupal::entityTypeManager()
+ ->getViewBuilder('node')
+ ->view($this->node, 'teaser');
$html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parses front page where the node is displayed in its teaser form.
diff --git a/core/modules/rdf/tests/src/Functional/ImageFieldAttributesTest.php b/core/modules/rdf/tests/src/Functional/ImageFieldAttributesTest.php
index bd62f1b009..22d786b71e 100644
--- a/core/modules/rdf/tests/src/Functional/ImageFieldAttributesTest.php
+++ b/core/modules/rdf/tests/src/Functional/ImageFieldAttributesTest.php
@@ -87,7 +87,9 @@ public function testNodeTeaser() {
->save();
// Render the teaser.
- $node_render_array = node_view($this->node, 'teaser');
+ $node_render_array = \Drupal::entityTypeManager()
+ ->getViewBuilder('node')
+ ->view($this->node, 'teaser');
$html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parse the teaser.
diff --git a/core/modules/rdf/tests/src/Kernel/Field/FieldRdfaTestBase.php b/core/modules/rdf/tests/src/Kernel/Field/FieldRdfaTestBase.php
index 7d8e54bf77..5c3479fdf9 100644
--- a/core/modules/rdf/tests/src/Kernel/Field/FieldRdfaTestBase.php
+++ b/core/modules/rdf/tests/src/Kernel/Field/FieldRdfaTestBase.php
@@ -90,7 +90,9 @@ protected function assertFormatterRdfa($formatter, $property, $expected_rdf_valu
entity_get_display('entity_test', 'entity_test', 'default')
->setComponent($this->fieldName, $formatter)
->save();
- $build = entity_view($this->entity, 'default');
+ $build = \Drupal::entityTypeManager()
+ ->getViewBuilder($this->entity->getEntityTypeId())
+ ->view($this->entity, 'default');
$output = \Drupal::service('renderer')->renderRoot($build);
$graph = new \EasyRdf_Graph($this->uri, $output, 'rdfa');
$this->setRawContent($output);
diff --git a/core/modules/system/tests/src/Functional/Theme/TwigDebugMarkupTest.php b/core/modules/system/tests/src/Functional/Theme/TwigDebugMarkupTest.php
index 9fe89fd58b..85f44d437f 100644
--- a/core/modules/system/tests/src/Functional/Theme/TwigDebugMarkupTest.php
+++ b/core/modules/system/tests/src/Functional/Theme/TwigDebugMarkupTest.php
@@ -43,7 +43,8 @@ public function testTwigDebugMarkup() {
// Create a node and test different features of the debug markup.
$node = $this->drupalCreateNode();
- $build = node_view($node);
+ $builder = \Drupal::entityTypeManager()->getViewBuilder('node');
+ $build = $builder->view($node);
$output = $renderer->renderRoot($build);
$this->assertTrue(strpos($output, '') !== FALSE, 'Twig debug markup found in theme output when debug is enabled.');
$this->assertTrue(strpos($output, "THEME HOOK: 'node'") !== FALSE, 'Theme call information found.');
@@ -55,7 +56,7 @@ public function testTwigDebugMarkup() {
// Create another node and make sure the template suggestions shown in the
// debug markup are correct.
$node2 = $this->drupalCreateNode();
- $build = node_view($node2);
+ $build = $builder->view($node2);
$output = $renderer->renderRoot($build);
$this->assertTrue(strpos($output, '* node--2--full' . $extension . PHP_EOL . ' * node--2' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.');
@@ -63,7 +64,7 @@ public function testTwigDebugMarkup() {
// debug markup are correct.
$node3 = $this->drupalCreateNode();
$build = ['#theme' => 'node__foo__bar'];
- $build += node_view($node3);
+ $build += $builder->view($node3);
$output = $renderer->renderRoot($build);
$this->assertTrue(strpos($output, "THEME HOOK: 'node__foo__bar'") !== FALSE, 'Theme call information found.');
$this->assertTrue(strpos($output, '* node--foo--bar' . $extension . PHP_EOL . ' * node--foo' . $extension . PHP_EOL . ' * node--<script type="text/javascript">alert('yo');</script>' . $extension . PHP_EOL . ' * node--3--full' . $extension . PHP_EOL . ' * node--3' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.');
@@ -75,7 +76,7 @@ public function testTwigDebugMarkup() {
$this->rebuildContainer();
$this->resetAll();
- $build = node_view($node);
+ $build = $builder->view($node);
$output = $renderer->renderRoot($build);
$this->assertFalse(strpos($output, '') !== FALSE, 'Twig debug markup not found in theme output when debug is disabled.');
}
diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
index 652ba32d07..ab7f88ebf6 100644
--- a/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -197,9 +197,18 @@ function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $c
* @return array
* A $page element suitable for use by
* \Drupal\Core\Render\RendererInterface::render().
+ *
+ * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use
+ * \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->view()
+ * instead.
+ *
+ * @see https://www.drupal.org/node/3033656
*/
function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) {
- return entity_view($term, $view_mode, $langcode);
+ @trigger_error("taxonomy_term_view() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->view() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED);
+ return \Drupal::entityTypeManager()
+ ->getViewBuilder('taxonomy_term')
+ ->view($term, $view_mode, $langcode);
}
/**
@@ -216,9 +225,18 @@ function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) {
* @return array
* An array in the format expected by
* \Drupal\Core\Render\RendererInterface::render().
+ *
+ * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use
+ * \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->viewMultiple()
+ * instead.
+ *
+ * @see https://www.drupal.org/node/3033656
*/
function taxonomy_term_view_multiple(array $terms, $view_mode = 'full', $langcode = NULL) {
- return entity_view_multiple($terms, $view_mode, $langcode);
+ @trigger_error("taxonomy_term_view_multiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->viewMultiple() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED);
+ return \Drupal::entityTypeManager()
+ ->getViewBuilder('taxonomy_term')
+ ->viewMultiple($terms, $view_mode, $langcode);
}
/**
diff --git a/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php b/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php
index 429e6fdafd..7e1595ecc9 100644
--- a/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php
+++ b/core/modules/taxonomy/tests/src/Kernel/TaxonomyLegacyTest.php
@@ -56,4 +56,18 @@ public function testEntityLegacyCode() {
$this->assertInstanceOf(VocabularyInterface::class, taxonomy_vocabulary_load($vocab->id()));
}
+ /**
+ * @expectedDeprecation taxonomy_term_view() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->view() instead. See https://www.drupal.org/node/3033656
+ * @expectedDeprecation taxonomy_term_view_multiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('taxonomy_term')->viewMultiple() instead. See https://www.drupal.org/node/3033656
+ */
+ public function testTaxonomyTermView() {
+ $entity = $this->createTerm($this->createVocabulary());
+ $this->assertNotEmpty(taxonomy_term_view($entity));
+ $entities = [
+ $this->createTerm($this->createVocabulary()),
+ $this->createTerm($this->createVocabulary()),
+ ];
+ $this->assertEquals(4, count(taxonomy_term_view_multiple($entities)));
+ }
+
}
diff --git a/core/modules/tour/tour.module b/core/modules/tour/tour.module
index ce9f309247..e6bbd2ae63 100644
--- a/core/modules/tour/tour.module
+++ b/core/modules/tour/tour.module
@@ -94,7 +94,9 @@ function tour_page_bottom(array &$page_bottom) {
}
}
if (!empty($tours)) {
- $page_bottom['tour'] = entity_view_multiple($tours, 'full');
+ $page_bottom['tour'] = \Drupal::entityTypeManager()
+ ->getViewBuilder('tour')
+ ->viewMultiple($tours, 'full');
}
}
}
diff --git a/core/modules/user/tests/src/Kernel/UserFieldsTest.php b/core/modules/user/tests/src/Kernel/UserFieldsTest.php
index 672ddb065e..321792ecc6 100644
--- a/core/modules/user/tests/src/Kernel/UserFieldsTest.php
+++ b/core/modules/user/tests/src/Kernel/UserFieldsTest.php
@@ -42,7 +42,9 @@ public function testUserFields() {
'name' => 'foobar',
'mail' => 'foobar@example.com',
]);
- $build = user_view($user);
+ $build = \Drupal::entityTypeManager()
+ ->getViewBuilder('user')
+ ->view($user);
$output = \Drupal::service('renderer')->renderRoot($build);
$this->setRawContent($output);
$userEmail = $user->getEmail();
diff --git a/core/modules/user/tests/src/Kernel/UserLegacyTest.php b/core/modules/user/tests/src/Kernel/UserLegacyTest.php
index 7decba06f8..cdf4e9751f 100644
--- a/core/modules/user/tests/src/Kernel/UserLegacyTest.php
+++ b/core/modules/user/tests/src/Kernel/UserLegacyTest.php
@@ -45,4 +45,18 @@ public function testEntityLegacyCode() {
$this->assertInstanceOf(UserInterface::class, user_load(1));
}
+ /**
+ * @expectedDeprecation user_view() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->view() instead. See https://www.drupal.org/node/3033656
+ * @expectedDeprecation user_view_multiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->viewMultiple() instead. See https://www.drupal.org/node/3033656
+ */
+ public function testUserView() {
+ $entity = User::create();
+ $this->assertNotEmpty(user_view($entity));
+ $entities = [
+ User::create(),
+ User::create(),
+ ];
+ $this->assertEquals(4, count(user_view_multiple($entities)));
+ }
+
}
diff --git a/core/modules/user/tests/src/Kernel/WhosOnlineBlockTest.php b/core/modules/user/tests/src/Kernel/WhosOnlineBlockTest.php
index 2779090700..85283c68fa 100644
--- a/core/modules/user/tests/src/Kernel/WhosOnlineBlockTest.php
+++ b/core/modules/user/tests/src/Kernel/WhosOnlineBlockTest.php
@@ -106,7 +106,9 @@ public function testWhosOnlineBlock() {
// Test the rendering of a block.
$entity = Block::load('views_block__who_s_online_who_s_online_block');
- $output = entity_view($entity, 'block');
+ $output = \Drupal::entityTypeManager()
+ ->getViewBuilder($entity->getEntityTypeId())
+ ->view($entity, 'block');
$this->setRawContent($this->renderer->renderRoot($output));
$this->assertRaw('2 users', 'Correct number of online users (2 users).');
$this->assertText($user1->getAccountName(), 'Active user 1 found in online list.');
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index f46d61e0cb..d7b989ae0d 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -905,9 +905,17 @@ function user_delete_multiple(array $uids) {
*
* @return array
* An array as expected by \Drupal\Core\Render\RendererInterface::render().
+ *
+ * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use
+ * \Drupal::entityTypeManager()->getViewBuilder('user')->view() instead.
+ *
+ * @see https://www.drupal.org/node/3033656
*/
function user_view($account, $view_mode = 'full', $langcode = NULL) {
- return entity_view($account, $view_mode, $langcode);
+ @trigger_error("user_view() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->view() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED);
+ return \Drupal::entityTypeManager()
+ ->getViewBuilder('user')
+ ->view($account, $view_mode, $langcode);
}
/**
@@ -924,9 +932,18 @@ function user_view($account, $view_mode = 'full', $langcode = NULL) {
* @return array
* An array in the format expected by
* \Drupal\Core\Render\RendererInterface::render().
+ *
+ * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use
+ * \Drupal::entityTypeManager()->getViewBuilder('user')->viewMultiple()
+ * instead.
+ *
+ * @see https://www.drupal.org/node/3033656
*/
function user_view_multiple($accounts, $view_mode = 'full', $langcode = NULL) {
- return entity_view_multiple($accounts, $view_mode, $langcode);
+ @trigger_error("user_view_multiple() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder('user')->viewMultiple() instead. See https://www.drupal.org/node/3033656", E_USER_DEPRECATED);
+ return \Drupal::entityTypeManager()
+ ->getViewBuilder('user')
+ ->viewMultiple($accounts, $view_mode, $langcode);
}
/**
diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php
index ff13f6c2b2..0020583e6e 100644
--- a/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityLegacyTest.php
@@ -51,4 +51,18 @@ public function testEntityLegacyCode() {
$this->assertInstanceOf(EntityInterface::class, entity_load('entity_test', 1));
}
+ /**
+ * @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 https://www.drupal.org/node/3033656
+ * @expectedDeprecation entity_view_multiple() is deprecated in Drupal 8.0.0 and will be removed before Drupal 9.0.0. Use \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId())->viewMultiple($entities, $view_mode, $langcode) instead. See https://www.drupal.org/node/3033656
+ */
+ public function testEntityView() {
+ $entity = EntityTest::create();
+ $this->assertNotEmpty(entity_view($entity, 'default'));
+ $entities = [
+ EntityTest::create(),
+ EntityTest::create(),
+ ];
+ $this->assertEquals(4, count(entity_view_multiple($entities, 'default')));
+ }
+
}