Commit f950d08b authored by larowlan's avatar larowlan

Issue #2974253 by andypost, legolasbo, mikelutz, Gábor Hojtsy: Remove...

Issue #2974253 by andypost, legolasbo, mikelutz, Gábor Hojtsy: Remove remaining usages of entity_view and entity_view_multiple from core
parent a80dcbe3
...@@ -335,10 +335,12 @@ function entity_page_label(EntityInterface $entity, $langcode = NULL) { ...@@ -335,10 +335,12 @@ function entity_page_label(EntityInterface $entity, $langcode = NULL) {
* return $view_builder->view($entity, $view_mode, $langcode); * return $view_builder->view($entity, $view_mode, $langcode);
* @endcode * @endcode
* *
* @see https://www.drupal.org/node/3033656
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getViewBuilder() * @see \Drupal\Core\Entity\EntityTypeManagerInterface::getViewBuilder()
* @see \Drupal\Core\Entity\EntityViewBuilderInterface::view() * @see \Drupal\Core\Entity\EntityViewBuilderInterface::view()
*/ */
function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $reset = FALSE) { 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()); $render_controller = \Drupal::entityManager()->getViewBuilder($entity->getEntityTypeId());
if ($reset) { if ($reset) {
$render_controller->resetCache([$entity]); $render_controller->resetCache([$entity]);
...@@ -373,10 +375,12 @@ function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $res ...@@ -373,10 +375,12 @@ function entity_view(EntityInterface $entity, $view_mode, $langcode = NULL, $res
* return $view_builder->viewMultiple($entities, $view_mode, $langcode); * return $view_builder->viewMultiple($entities, $view_mode, $langcode);
* @endcode * @endcode
* *
* @see https://www.drupal.org/node/3033656
* @see \Drupal\Core\Entity\EntityTypeManagerInterface::getViewBuilder() * @see \Drupal\Core\Entity\EntityTypeManagerInterface::getViewBuilder()
* @see \Drupal\Core\Entity\EntityViewBuilderInterface::viewMultiple() * @see \Drupal\Core\Entity\EntityViewBuilderInterface::viewMultiple()
*/ */
function entity_view_multiple(array $entities, $view_mode, $langcode = NULL, $reset = FALSE) { 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()); $render_controller = \Drupal::entityManager()->getViewBuilder(reset($entities)->getEntityTypeId());
if ($reset) { if ($reset) {
$render_controller->resetCache($entities); $render_controller->resetCache($entities);
......
...@@ -83,7 +83,8 @@ public function testBasicRendering() { ...@@ -83,7 +83,8 @@ public function testBasicRendering() {
// Test the rendering of a block. // Test the rendering of a block.
$entity = Block::load('test_block1'); $entity = Block::load('test_block1');
$output = entity_view($entity, 'block'); $builder = \Drupal::entityTypeManager()->getViewBuilder('block');
$output = $builder->view($entity, 'block');
$expected = []; $expected = [];
$expected[] = '<div id="block-test-block1">'; $expected[] = '<div id="block-test-block1">';
$expected[] = ' '; $expected[] = ' ';
...@@ -107,7 +108,7 @@ public function testBasicRendering() { ...@@ -107,7 +108,7 @@ public function testBasicRendering() {
], ],
]); ]);
$entity->save(); $entity->save();
$output = entity_view($entity, 'block'); $output = $builder->view($entity, 'block');
$expected = []; $expected = [];
$expected[] = '<div id="block-test-block2">'; $expected[] = '<div id="block-test-block2">';
$expected[] = ' '; $expected[] = ' ';
......
...@@ -272,10 +272,15 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie ...@@ -272,10 +272,15 @@ function comment_node_view_alter(array &$build, EntityInterface $node, EntityVie
* An array as expected by \Drupal\Core\Render\RendererInterface::render(). * An array as expected by \Drupal\Core\Render\RendererInterface::render().
* *
* @deprecated in Drupal 8.x and will be removed before Drupal 9.0. * @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) { 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 ...@@ -296,12 +301,16 @@ function comment_view(CommentInterface $comment, $view_mode = 'full', $langcode
* \Drupal\Core\Render\RendererInterface::render(). * \Drupal\Core\Render\RendererInterface::render().
* *
* @deprecated in Drupal 8.x and will be removed before Drupal 9.0. * @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() * @see \Drupal\Core\Render\RendererInterface::render()
*/ */
function comment_view_multiple($comments, $view_mode = 'full', $langcode = NULL) { 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 ...@@ -594,7 +603,9 @@ function comment_preview(CommentInterface $comment, FormStateInterface $form_sta
$field_name = $comment->getFieldName(); $field_name = $comment->getFieldName();
$entity = clone $entity; $entity = clone $entity;
$entity->$field_name->status = CommentItemInterface::HIDDEN; $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; $preview_build['comment_output_below'] = $build;
...@@ -652,7 +663,9 @@ function template_preprocess_comment(&$variables) { ...@@ -652,7 +663,9 @@ function template_preprocess_comment(&$variables) {
if (theme_get_setting('features.comment_user_picture')) { if (theme_get_setting('features.comment_user_picture')) {
// To change user picture settings (for instance, image style), edit the // To change user picture settings (for instance, image style), edit the
// 'compact' view mode on the User entity. // '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 { else {
$variables['user_picture'] = []; $variables['user_picture'] = [];
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
class EntityLink extends FieldPluginBase { 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 * @var array
*/ */
...@@ -61,7 +61,11 @@ public function preRender(&$values) { ...@@ -61,7 +61,11 @@ public function preRender(&$values) {
$entities[$entity->id()] = $entity; $entities[$entity->id()] = $entity;
} }
if ($entities) { 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);
} }
} }
......
<?php
namespace Drupal\Tests\comment\Kernel;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
/**
* Tests legacy comment functionality.
*
* @group comment
* @group legacy
*/
class CommentLegacyTest extends EntityKernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['comment'];
/**
* The entity to which the comments are attached to.
*
* @var \Drupal\entity_test\Entity\EntityTest
*/
protected $entity;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->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)));
}
}
...@@ -141,7 +141,9 @@ function contact_mail($key, &$message, $params) { ...@@ -141,7 +141,9 @@ function contact_mail($key, &$message, $params) {
case 'page_copy': case 'page_copy':
$message['subject'] .= t('[@form] @subject', $variables, $options); $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); $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); $message['body'][] = \Drupal::service('renderer')->renderPlain($build);
break; break;
...@@ -160,7 +162,9 @@ function contact_mail($key, &$message, $params) { ...@@ -160,7 +162,9 @@ function contact_mail($key, &$message, $params) {
$message['body'][] = t('Hello @recipient-name,', $variables, $options); $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("@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); $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); $message['body'][] = \Drupal::service('renderer')->renderPlain($build);
break; break;
} }
......
...@@ -158,7 +158,9 @@ public function testAccess() { ...@@ -158,7 +158,9 @@ public function testAccess() {
->save(); ->save();
// Invoke entity view. // 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. // 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])); $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]));
......
...@@ -243,7 +243,9 @@ public function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $tex ...@@ -243,7 +243,9 @@ public function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $tex
// Render a cloned node, so that we do not alter the original. // Render a cloned node, so that we do not alter the original.
$clone = clone $node; $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); $output = (string) \Drupal::service('renderer')->renderRoot($element);
$this->verbose(t('Rendered node - view mode: @view_mode', ['@view_mode' => $view_mode]) . '<hr />' . $output); $this->verbose(t('Rendered node - view mode: @view_mode', ['@view_mode' => $view_mode]) . '<hr />' . $output);
......
...@@ -142,7 +142,9 @@ public function testFileItem() { ...@@ -142,7 +142,9 @@ public function testFileItem() {
$entity = EntityTest::create(); $entity = EntityTest::create();
$entity->file_test = ['entity' => $file3]; $entity->file_test = ['entity' => $file3];
$uri = $file3->getFileUri(); $uri = $file3->getFileUri();
$output = entity_view($entity, 'default'); $output = \Drupal::entityTypeManager()
->getViewBuilder('entity_test')
->view($entity, 'default');
\Drupal::service('renderer')->renderRoot($output); \Drupal::service('renderer')->renderRoot($output);
$this->assertTrue(!empty($entity->file_test->entity)); $this->assertTrue(!empty($entity->file_test->entity));
$this->assertEqual($entity->file_test->entity->getFileUri(), $uri); $this->assertEqual($entity->file_test->entity->getFileUri(), $uri);
......
...@@ -681,7 +681,9 @@ function template_preprocess_node(&$variables) { ...@@ -681,7 +681,9 @@ function template_preprocess_node(&$variables) {
// 'compact' view mode on the User entity. Note that the 'compact' // 'compact' view mode on the User entity. Note that the 'compact'
// view mode might not be configured, so remember to always check the // view mode might not be configured, so remember to always check the
// theme setting first. // theme setting first.
$variables['author_picture'] = user_view($node->getOwner(), 'compact'); $variables['author_picture'] = \Drupal::entityTypeManager()
->getViewBuilder('user')
->view($node->getOwner(), 'compact');
} }
} }
} }
...@@ -853,9 +855,17 @@ function node_get_recent($number = 10) { ...@@ -853,9 +855,17 @@ function node_get_recent($number = 10) {
* *
* @return array * @return array
* An array as expected by \Drupal\Core\Render\RendererInterface::render(). * 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) { 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);
} }
/** /**
...@@ -872,9 +882,18 @@ function node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL) { ...@@ -872,9 +882,18 @@ function node_view(NodeInterface $node, $view_mode = 'full', $langcode = NULL) {
* @return array * @return array
* An array in the format expected by * An array in the format expected by
* \Drupal\Core\Render\RendererInterface::render(). * \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) { 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);
} }
/** /**
......
...@@ -22,9 +22,12 @@ class UnpublishByKeywordNode extends ConfigurableActionBase { ...@@ -22,9 +22,12 @@ class UnpublishByKeywordNode extends ConfigurableActionBase {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function execute($node = NULL) { 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) { foreach ($this->configuration['keywords'] as $keyword) {
$elements = node_view(clone $node); if (strpos($render, $keyword) !== FALSE || strpos($node->label(), $keyword) !== FALSE) {
if (strpos(\Drupal::service('renderer')->render($elements), $keyword) !== FALSE || strpos($node->label(), $keyword) !== FALSE) {
$node->setUnpublished(); $node->setUnpublished();
$node->save(); $node->save();
break; break;
......
...@@ -129,7 +129,9 @@ public function render($row) { ...@@ -129,7 +129,9 @@ public function render($row) {
$build_mode = $display_mode; $build_mode = $display_mode;
$build = node_view($node, $build_mode); $build = \Drupal::entityTypeManager()
->getViewBuilder('node')
->view($node, $build_mode);
unset($build['#theme']); unset($build['#theme']);
if (!empty($node->rss_namespaces)) { if (!empty($node->rss_namespaces)) {
......
...@@ -63,4 +63,18 @@ public function testEntityLegacyCode() { ...@@ -63,4 +63,18 @@ public function testEntityLegacyCode() {
$this->assertInstanceOf(NodeTypeInterface::class, node_type_load('page')); $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)));
}
} }
...@@ -102,7 +102,9 @@ public function testNodeTeaser() { ...@@ -102,7 +102,9 @@ public function testNodeTeaser() {
]); ]);
// Render the node. // 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); $html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parse the teaser. // Parse the teaser.
......
...@@ -77,7 +77,9 @@ protected function setUp() { ...@@ -77,7 +77,9 @@ protected function setUp() {
*/ */
public function testNodeTeaser() { public function testNodeTeaser() {
// Render the teaser. // 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); $html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parses front page where the node is displayed in its teaser form. // Parses front page where the node is displayed in its teaser form.
......
...@@ -89,7 +89,9 @@ public function testNodeTeaser() { ...@@ -89,7 +89,9 @@ public function testNodeTeaser() {
->save(); ->save();
// Render the teaser. // 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); $html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parse the teaser. // Parse the teaser.
......
...@@ -91,7 +91,9 @@ protected function assertFormatterRdfa($formatter, $property, $expected_rdf_valu ...@@ -91,7 +91,9 @@ protected function assertFormatterRdfa($formatter, $property, $expected_rdf_valu
->getViewDisplay('entity_test', 'entity_test') ->getViewDisplay('entity_test', 'entity_test')
->setComponent($this->fieldName, $formatter) ->setComponent($this->fieldName, $formatter)
->save(); ->save();
$build = entity_view($this->entity, 'default'); $build = \Drupal::entityTypeManager()
->getViewBuilder($this->entity->getEntityTypeId())
->view($this->entity, 'default');
$output = \Drupal::service('renderer')->renderRoot($build); $output = \Drupal::service('renderer')->renderRoot($build);
$graph = new \EasyRdf_Graph($this->uri, $output, 'rdfa'); $graph = new \EasyRdf_Graph($this->uri, $output, 'rdfa');
$this->setRawContent($output); $this->setRawContent($output);
......
...@@ -43,7 +43,8 @@ public function testTwigDebugMarkup() { ...@@ -43,7 +43,8 @@ public function testTwigDebugMarkup() {
// Create a node and test different features of the debug markup. // Create a node and test different features of the debug markup.
$node = $this->drupalCreateNode(); $node = $this->drupalCreateNode();
$build = node_view($node); $builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$build = $builder->view($node);
$output = $renderer->renderRoot($build); $output = $renderer->renderRoot($build);
$this->assertTrue(strpos($output, '<!-- THEME DEBUG -->') !== FALSE, 'Twig debug markup found in theme output when debug is enabled.'); $this->assertTrue(strpos($output, '<!-- THEME DEBUG -->') !== FALSE, 'Twig debug markup found in theme output when debug is enabled.');
$this->assertTrue(strpos($output, "THEME HOOK: 'node'") !== FALSE, 'Theme call information found.'); $this->assertTrue(strpos($output, "THEME HOOK: 'node'") !== FALSE, 'Theme call information found.');
...@@ -55,7 +56,7 @@ public function testTwigDebugMarkup() { ...@@ -55,7 +56,7 @@ public function testTwigDebugMarkup() {
// Create another node and make sure the template suggestions shown in the // Create another node and make sure the template suggestions shown in the
// debug markup are correct. // debug markup are correct.
$node2 = $this->drupalCreateNode(); $node2 = $this->drupalCreateNode();
$build = node_view($node2); $build = $builder->view($node2);
$output = $renderer->renderRoot($build); $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.'); $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() { ...@@ -63,7 +64,7 @@ public function testTwigDebugMarkup() {
// debug markup are correct. // debug markup are correct.
$node3 = $this->drupalCreateNode(); $node3 = $this->drupalCreateNode();
$build = ['#theme' => 'node__foo__bar']; $build = ['#theme' => 'node__foo__bar'];
$build += node_view($node3); $build += $builder->view($node3);
$output = $renderer->renderRoot($build); $output = $renderer->renderRoot($build);
$this->assertTrue(strpos($output, "THEME HOOK: 'node__foo__bar'") !== FALSE, 'Theme call information found.'); $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--&lt;script type=&quot;text/javascript&quot;&gt;alert(&#039;yo&#039;);&lt;/script&gt;' . $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.'); $this->assertTrue(strpos($output, '* node--foo--bar' . $extension . PHP_EOL . ' * node--foo' . $extension . PHP_EOL . ' * node--&lt;script type=&quot;text/javascript&quot;&gt;alert(&#039;yo&#039;);&lt;/script&gt;' . $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() { ...@@ -75,7 +76,7 @@ public function testTwigDebugMarkup() {
$this->rebuildContainer(); $this->rebuildContainer();
$this->resetAll(); $this->resetAll();
$build = node_view($node); $build = $builder->view($node);
$output = $renderer->renderRoot($build); $output = $renderer->renderRoot($build);
$this->assertFalse(strpos($output, '<!-- THEME DEBUG -->') !== FALSE, 'Twig debug markup not found in theme output when debug is disabled.'); $this->assertFalse(strpos($output, '<!-- THEME DEBUG -->') !== FALSE, 'Twig debug markup not found in theme output when debug is disabled.');
} }
......
...@@ -182,9 +182,18 @@ function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $c ...@@ -182,9 +182,18 @@ function taxonomy_check_vocabulary_hierarchy(VocabularyInterface $vocabulary, $c
* @return array * @return array
* A $page element suitable for use by * A $page element suitable for use by
* \Drupal\Core\Render\RendererInterface::render(). * \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) { 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);
} }
/** /**
...@@ -201,9 +210,18 @@ function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) { ...@@ -201,9 +210,18 @@ function taxonomy_term_view(Term $term, $view_mode = 'full', $langcode = NULL) {
* @return array * @return array
* An array in the format expected by * An array in the format expected by
* \Drupal\Core\Render\RendererInterface::render(). * \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) { 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);
} }
/** /**
......
...@@ -56,4 +56,18 @@ public function testEntityLegacyCode() { ...@@ -56,4 +56,18 @@ public function testEntityLegacyCode() {
$this->assertInstanceOf(VocabularyInterface::class, taxonomy_vocabulary_load($vocab->id())); $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)));
}
} }
...@@ -94,7 +94,9 @@ function tour_page_bottom(array &$page_bottom) { ...@@ -94,7 +94,9 @@ function tour_page_bottom(array &$page_bottom) {
} }
} }
if (!empty($tours)) { if (!empty($tours)) {
$page_bottom['tour'] = entity_view_multiple($tours, 'full'); $page_bottom['tour'] = \Drupal::entityTypeManager()