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) {
* 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]);
......@@ -373,10 +375,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);
......
......@@ -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[] = '<div id="block-test-block1">';
$expected[] = ' ';
......@@ -107,7 +108,7 @@ public function testBasicRendering() {
],
]);
$entity->save();
$output = entity_view($entity, 'block');
$output = $builder->view($entity, 'block');
$expected = [];
$expected[] = '<div id="block-test-block2">';
$expected[] = ' ';
......
......@@ -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'] = [];
......
......@@ -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);
}
}
......
<?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) {
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;
......@@ -160,7 +162,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;
}
......
......@@ -158,7 +158,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]));
......
......@@ -243,7 +243,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]) . '<hr />' . $output);
......
......@@ -142,7 +142,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);
......
......@@ -681,7 +681,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');
}
}
}
......@@ -853,9 +855,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);
}
/**
......@@ -872,9 +882,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);
}
/**
......
......@@ -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;
......
......@@ -129,7 +129,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)) {
......
......@@ -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)));
}
}
......@@ -102,7 +102,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.
......
......@@ -77,7 +77,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.
......
......@@ -89,7 +89,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.
......
......@@ -91,7 +91,9 @@ protected function assertFormatterRdfa($formatter, $property, $expected_rdf_valu
->getViewDisplay('entity_test', 'entity_test')
->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);
......
......@@ -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, '<!-- 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.');
......@@ -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--&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() {
$this->rebuildContainer();
$this->resetAll();
$build = node_view($node);
$build = $builder->view($node);
$output = $renderer->renderRoot($build);
$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
* @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);
}
/**
......@@ -201,9 +210,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);
}
/**
......
......@@ -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)));
}
}
......@@ -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');
}
}
}
......
......@@ -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();
......
......@@ -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)));
}
}
......@@ -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.');
......
......@@ -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);
}
/**
......
......@@ -91,4 +91,18 @@ public function testLegacyDisplayFunctions() {
$this->assertEquals('entity_test.entity_test.default', $form_display->id());
}
/**
* @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')));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment