diff --git a/core/modules/block/block.api.php b/core/modules/block/block.api.php index 7f5269f52..a159671 100644 --- a/core/modules/block/block.api.php +++ b/core/modules/block/block.api.php @@ -72,8 +72,8 @@ * If the module wishes to act on the rendered HTML of the block rather than * the structured content array, it may use this hook to add a #post_render * callback. Alternatively, it could also implement hook_preprocess_HOOK() for - * block.html.twig. See drupal_render() and _theme() documentation respectively - * for details. + * block.html.twig. See \Drupal\Core\Render\Renderer::render() and _theme() + * documentation respectively for details. * * In addition to hook_block_view_alter(), which is called for all blocks, there * is hook_block_view_BASE_BLOCK_ID_alter(), which can be used to target a diff --git a/core/modules/block/src/Controller/BlockListController.php b/core/modules/block/src/Controller/BlockListController.php index 72aa445..082acb3 100644 --- a/core/modules/block/src/Controller/BlockListController.php +++ b/core/modules/block/src/Controller/BlockListController.php @@ -24,7 +24,7 @@ class BlockListController extends EntityListController { * The current request. * * @return array - * A render array as expected by drupal_render(). + * A render array as expected by renderer service. */ public function listing($theme = NULL, Request $request = NULL) { $theme = $theme ?: $this->config('system.theme')->get('default'); diff --git a/core/modules/block/src/Tests/BlockViewBuilderTest.php b/core/modules/block/src/Tests/BlockViewBuilderTest.php index 02fec0f..b81b975 100644 --- a/core/modules/block/src/Tests/BlockViewBuilderTest.php +++ b/core/modules/block/src/Tests/BlockViewBuilderTest.php @@ -44,6 +44,13 @@ class BlockViewBuilderTest extends KernelTestBase { protected $controller; /** + * The rendering service. + * + * @var \Drupal\Core\Render\Renderer + */ + protected $renderer; + + /** * {@inheritdoc} */ protected function setUp() { @@ -64,6 +71,8 @@ protected function setUp() { $this->block->save(); $this->container->get('cache.render')->deleteAll(); + + $this->renderer = $this->container->get('renderer'); } /** @@ -90,7 +99,7 @@ public function testBasicRendering() { $expected[] = ' '; $expected[] = ''; $expected_output = implode("\n", $expected); - $this->assertEqual(drupal_render($output), $expected_output); + $this->assertEqual($this->renderer->render($output), $expected_output); // Reset the HTML IDs so that the next render is not affected. Html::resetSeenIds(); @@ -115,7 +124,7 @@ public function testBasicRendering() { $expected[] = ' '; $expected[] = ''; $expected_output = implode("\n", $expected); - $this->assertEqual(drupal_render($output), $expected_output); + $this->assertEqual($this->renderer->render($output), $expected_output); } /** @@ -144,7 +153,7 @@ public function testBlockViewBuilderCache() { * @see ::testBlockViewBuilderCache() */ protected function verifyRenderCacheHandling() { - // Force a request via GET so we can get drupal_render() cache working. + // Force a request via GET so we can get renderer service cache working. $request = \Drupal::request(); $request_method = $request->server->get('REQUEST_METHOD'); $request->setMethod('GET'); @@ -152,7 +161,7 @@ protected function verifyRenderCacheHandling() { // Test that a cache entry is created. $build = $this->getBlockRenderArray(); $cid = 'entity_view:block:test_block:en:core'; - drupal_render($build); + $this->renderer->render($build); $this->assertTrue($this->container->get('cache.render')->get($cid), 'The block render element has been cached.'); // Re-save the block and check that the cache entry has been deleted. @@ -166,7 +175,7 @@ protected function verifyRenderCacheHandling() { // removes it. $build['#block'] = $this->block; - drupal_render($build); + $this->renderer->render($build); $this->assertTrue($this->container->get('cache.render')->get($cid), 'The block render element has been cached.'); $this->block->delete(); $this->assertFalse($this->container->get('cache.render')->get($cid), 'The block render cache entry has been cleared when the block was deleted.'); @@ -181,17 +190,17 @@ protected function verifyRenderCacheHandling() { public function testBlockViewBuilderAlter() { // Establish baseline. $build = $this->getBlockRenderArray(); - $this->assertIdentical(drupal_render($build), 'Llamas > unicorns!'); + $this->assertIdentical($this->renderer->render($build), 'Llamas > unicorns!'); // Enable the block view alter hook that adds a suffix, for basic testing. \Drupal::state()->set('block_test_view_alter_suffix', TRUE); Cache::invalidateTags($this->block->getCacheTags()); $build = $this->getBlockRenderArray(); $this->assertTrue(isset($build['#suffix']) && $build['#suffix'] === '
Goodbye!', 'A block with content is altered.'); - $this->assertIdentical(drupal_render($build), 'Llamas > unicorns!
Goodbye!'); + $this->assertIdentical($this->renderer->render($build), 'Llamas > unicorns!
Goodbye!'); \Drupal::state()->set('block_test_view_alter_suffix', FALSE); - // Force a request via GET so we can get drupal_render() cache working. + // Force a request via GET so we can get renderer service cache working. $request = \Drupal::request(); $request_method = $request->server->get('REQUEST_METHOD'); $request->setMethod('GET'); @@ -209,7 +218,7 @@ public function testBlockViewBuilderAlter() { $expected_keys = array_merge($default_keys, array($alter_add_key)); $build = $this->getBlockRenderArray(); $this->assertIdentical($expected_keys, $build['#cache']['keys'], 'An altered cacheable block has the expected cache keys.'); - $this->assertIdentical(drupal_render($build), ''); + $this->assertIdentical($this->renderer->render($build), ''); $cache_entry = $this->container->get('cache.render')->get($cid); $this->assertTrue($cache_entry, 'The block render element has been cached with the expected cache ID.'); $expected_tags = array_merge($default_tags, ['rendered']); @@ -224,7 +233,7 @@ public function testBlockViewBuilderAlter() { $build = $this->getBlockRenderArray(); sort($build['#cache']['tags']); $this->assertIdentical($expected_tags, $build['#cache']['tags'], 'An altered cacheable block has the expected cache tags.'); - $this->assertIdentical(drupal_render($build), ''); + $this->assertIdentical($this->renderer->render($build), ''); $cache_entry = $this->container->get('cache.render')->get($cid); $this->assertTrue($cache_entry, 'The block render element has been cached with the expected cache ID.'); $expected_tags = array_merge($default_tags, [$alter_add_tag, 'rendered']); @@ -236,8 +245,8 @@ public function testBlockViewBuilderAlter() { // alter the eventual content. \Drupal::state()->set('block_test_view_alter_append_pre_render_prefix', TRUE); $build = $this->getBlockRenderArray(); - $this->assertFalse(isset($build['#prefix']), 'The appended #pre_render callback has not yet run before calling drupal_render().'); - $this->assertIdentical(drupal_render($build), 'Hiya!
'); + $this->assertFalse(isset($build['#prefix']), 'The appended #pre_render callback has not yet run before calling renderer service'); + $this->assertIdentical($this->renderer->render($build), 'Hiya!
'); $this->assertTrue(isset($build['#prefix']) && $build['#prefix'] === 'Hiya!
', 'A cached block without content is altered.'); // Restore the previous request method.