core/includes/common.inc | 2 +-
core/lib/Drupal/Core/Ajax/AjaxResponse.php | 6 ++--
.../Drupal/Core/Render/BareHtmlPageRenderer.php | 4 +--
core/lib/Drupal/Core/Render/Element/Actions.php | 2 +-
.../Core/Render/MainContent/HtmlRenderer.php | 10 +++----
core/lib/Drupal/Core/Render/Renderer.php | 21 ++++++++++----
.../block/src/Tests/BlockViewBuilderTest.php | 33 ++++++++++++++--------
.../src/Tests/BlockContentCacheTagsTest.php | 2 +-
core/modules/book/src/BookOutline.php | 3 +-
.../ckeditor/src/Plugin/Editor/CKEditor.php | 18 ++++++++++--
core/modules/comment/comment.module | 2 +-
.../comment/src/Form/CommentAdminOverview.php | 4 ++-
.../Tests/CommentDefaultFormatterCacheTagsTest.php | 17 +++++++++--
core/modules/config/src/Form/ConfigSync.php | 18 ++++++++++--
core/modules/contact/src/MessageViewBuilder.php | 6 ++--
.../contextual/src/ContextualController.php | 2 +-
.../datetime/src/Tests/DateTimeFieldTest.php | 2 +-
core/modules/field/field.module | 2 +-
.../field/src/Tests/Boolean/BooleanFieldTest.php | 2 +-
.../field/src/Tests/Email/EmailFieldTest.php | 2 +-
.../EntityReferenceFormatterTest.php | 10 +++++--
.../field/src/Tests/String/StringFieldTest.php | 2 +-
.../field_ui/src/Tests/ManageDisplayTest.php | 2 +-
core/modules/file/file.field.inc | 2 +-
.../src/Plugin/Field/FieldWidget/FileWidget.php | 2 +-
.../file/src/Tests/FileFieldDisplayTest.php | 2 +-
core/modules/file/src/Tests/FileItemTest.php | 2 +-
core/modules/forum/src/Tests/ForumTest.php | 4 +--
.../src/Tests/Views/HistoryTimestampTest.php | 2 +-
.../src/Plugin/Field/FieldWidget/ImageWidget.php | 2 +-
.../image/src/Tests/ImageDimensionsTest.php | 2 +-
.../image/src/Tests/ImageFieldDisplayTest.php | 23 +++++++++------
.../image/src/Tests/ImageThemeFunctionTest.php | 25 ++++++++++------
core/modules/link/src/Tests/LinkFieldTest.php | 2 +-
core/modules/node/src/Tests/SummaryLengthTest.php | 7 +++--
.../modules/node/src/Tests/Views/RowPluginTest.php | 6 ++--
.../quickedit/src/Tests/QuickEditLoadingTest.php | 2 +-
.../Tests/EntityReferenceFieldAttributesTest.php | 2 +-
.../rdf/src/Tests/Field/FieldRdfaTestBase.php | 2 +-
.../rdf/src/Tests/FileFieldAttributesTest.php | 2 +-
.../rdf/src/Tests/ImageFieldAttributesTest.php | 2 +-
.../src/Tests/ResponsiveImageFieldDisplayTest.php | 6 ++--
.../simpletest/src/Form/SimpletestResultsForm.php | 10 +++----
.../simpletest/src/Form/SimpletestTestForm.php | 32 +++++++++++++++++++--
.../simpletest/src/Tests/KernelTestBaseTest.php | 6 ++--
core/modules/system/src/Tests/Ajax/DialogTest.php | 2 +-
.../system/src/Tests/Common/AddFeedTest.php | 2 +-
.../src/Tests/Common/RenderElementTypesTest.php | 8 +++---
.../modules/system/src/Tests/Common/RenderTest.php | 2 +-
core/modules/system/src/Tests/Common/UrlTest.php | 18 ++++++++----
.../src/Tests/Entity/EntityTranslationTest.php | 11 +++++---
.../src/Tests/Entity/EntityViewBuilderTest.php | 17 +++++++----
.../modules/system/src/Tests/Form/CheckboxTest.php | 2 +-
core/modules/system/src/Tests/Form/FormTest.php | 2 +-
.../system/src/Tests/Theme/FunctionsTest.php | 6 ++--
.../system/src/Tests/Theme/TwigDebugMarkupTest.php | 10 ++++---
.../system/src/Tests/Theme/TwigEnvironmentTest.php | 8 ++++--
.../system/src/Tests/Theme/TwigFilterTest.php | 2 +-
.../system/src/Tests/Theme/TwigNamespaceTest.php | 2 +-
.../modules/system/src/Tests/Theme/TwigRawTest.php | 4 +--
.../src/Controller/CommonTestController.php | 3 +-
.../text/src/Tests/Formatter/TextFormatterTest.php | 2 +-
core/modules/text/src/Tests/TextFieldTest.php | 7 +++--
.../src/Plugin/views/style/StylePluginBase.php | 2 +-
.../src/Tests/Entity/RowEntityRenderersTest.php | 2 +-
.../views/src/Tests/Handler/AreaEntityTest.php | 8 ++++--
core/modules/views/src/Tests/Handler/AreaTest.php | 4 +--
.../views/src/Tests/Handler/AreaTextTest.php | 8 ++++--
.../views/src/Tests/Handler/AreaViewTest.php | 6 ++--
.../src/Tests/Handler/FieldFieldAccessTestBase.php | 4 +--
.../views/src/Tests/Handler/FieldUnitTest.php | 6 ++--
.../views/src/Tests/Handler/FieldWebTest.php | 18 ++++++------
.../modules/views/src/Tests/Plugin/DisplayTest.php | 17 +++++++----
.../views/src/Tests/Plugin/ExposedFormTest.php | 2 +-
core/modules/views/src/Tests/Plugin/PagerTest.php | 2 +-
.../views/src/Tests/Plugin/StyleGridTest.php | 2 +-
.../views/src/Tests/Plugin/StyleHtmlListTest.php | 4 +--
.../views/src/Tests/Plugin/StyleMappingTest.php | 2 +-
.../views/src/Tests/Plugin/StyleTableUnitTest.php | 6 ++--
core/modules/views/src/Tests/Plugin/StyleTest.php | 9 ++++--
.../src/Tests/Plugin/StyleUnformattedTest.php | 2 +-
core/modules/views/src/Tests/ViewElementTest.php | 12 +++++---
core/modules/views/src/Tests/ViewRenderTest.php | 2 +-
core/modules/views/src/Tests/ViewsTemplateTest.php | 2 +-
.../views_ui/src/Tests/CustomBooleanTest.php | 2 +-
.../Tests/Core/Render/RendererBubblingTest.php | 22 +++++++--------
.../Drupal/Tests/Core/Render/RendererTest.php | 22 +++++++--------
87 files changed, 375 insertions(+), 216 deletions(-)
diff --git a/core/includes/common.inc b/core/includes/common.inc
index 218bae4..e83fb6f 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -195,7 +195,7 @@ function drupal_get_html_head($render = TRUE) {
$elements = _drupal_add_html_head();
\Drupal::moduleHandler()->alter('html_head', $elements);
if ($render) {
- return drupal_render($elements);
+ return \Drupal::service('renderer')->renderPlain($elements);
}
else {
return $elements;
diff --git a/core/lib/Drupal/Core/Ajax/AjaxResponse.php b/core/lib/Drupal/Core/Ajax/AjaxResponse.php
index a83898d..7d67454 100644
--- a/core/lib/Drupal/Core/Ajax/AjaxResponse.php
+++ b/core/lib/Drupal/Core/Ajax/AjaxResponse.php
@@ -198,15 +198,15 @@ protected function ajaxRender(Request $request) {
$renderer = $this->getRenderer();
if (!empty($css_assets)) {
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css_assets);
- $resource_commands[] = new AddCssCommand($renderer->render($css_render_array));
+ $resource_commands[] = new AddCssCommand($renderer->renderPlain($css_render_array));
}
if (!empty($js_assets_header)) {
$js_header_render_array = \Drupal::service('asset.js.collection_renderer')->render($js_assets_header);
- $resource_commands[] = new PrependCommand('head', $renderer->render($js_header_render_array));
+ $resource_commands[] = new PrependCommand('head', $renderer->renderPlain($js_header_render_array));
}
if (!empty($js_assets_footer)) {
$js_footer_render_array = \Drupal::service('asset.js.collection_renderer')->render($js_assets_footer);
- $resource_commands[] = new AppendCommand('body', $renderer->render($js_footer_render_array));
+ $resource_commands[] = new AppendCommand('body', $renderer->renderPlain($js_footer_render_array));
}
foreach (array_reverse($resource_commands) as $resource_command) {
$this->addCommand($resource_command, TRUE);
diff --git a/core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php b/core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php
index c8012c6..58c5507 100644
--- a/core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php
+++ b/core/lib/Drupal/Core/Render/BareHtmlPageRenderer.php
@@ -59,12 +59,12 @@ public function renderBarePage(array $content, $title, $page_theme_property, arr
// \Drupal\Core\Render\MainContent\HtmlRenderer::renderResponse() for more
// information about this; the exact same pattern is used there and
// explained in detail there.
- $this->renderer->render($html['page'], TRUE);
+ $this->renderer->renderRoot($html['page']);
// Add the bare minimum of attachments from the system module and the
// current maintenance theme.
system_page_attachments($html['page']);
- return $this->renderer->render($html);
+ return $this->renderer->renderPlain($html);
}
}
diff --git a/core/lib/Drupal/Core/Render/Element/Actions.php b/core/lib/Drupal/Core/Render/Element/Actions.php
index 754f7f8..674e229 100644
--- a/core/lib/Drupal/Core/Render/Element/Actions.php
+++ b/core/lib/Drupal/Core/Render/Element/Actions.php
@@ -94,7 +94,7 @@ public static function preRenderActionsDropbutton(&$element, FormStateInterface
// Add this button to the corresponding dropbutton.
// @todo Change #type 'dropbutton' to be based on item-list.html.twig
// instead of links.html.twig to avoid this preemptive rendering.
- $button = drupal_render($element[$key]);
+ $button = \Drupal::service('renderer')->renderPlain($element[$key]);
$dropbuttons[$dropbutton]['#links'][$key] = array(
'title' => $button,
);
diff --git a/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php b/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
index d61bb24..05e38ec 100644
--- a/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
+++ b/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
@@ -126,14 +126,14 @@ public function renderResponse(array $main_content, Request $request, RouteMatch
// and hence may not replace any placeholders (because they might add yet
// more assets to be attached), and therefore it must be rendered with
// drupal_render(), not drupal_render_root().
- $this->renderer->render($html['page'], TRUE);
+ $this->renderer->renderRoot($html['page']);
if (isset($html['page_top'])) {
- $this->renderer->render($html['page_top'], TRUE);
+ $this->renderer->renderRoot($html['page_top']);
}
if (isset($html['page_bottom'])) {
- $this->renderer->render($html['page_bottom'], TRUE);
+ $this->renderer->renderRoot($html['page_bottom']);
}
- $content = $this->renderer->render($html);
+ $content = $this->renderer->renderPlain($html, FALSE);
$response = new CacheableResponse($content, 200,[
'Content-Type' => 'text/html; charset=UTF-8',
@@ -197,7 +197,7 @@ protected function prepare(array $main_content, Request $request, RouteMatchInte
// ::renderResponse().
// @todo Remove this once https://www.drupal.org/node/2359901 lands.
if (!empty($main_content)) {
- $this->renderer->render($main_content, FALSE);
+ $this->renderer->renderPlain($main_content, FALSE);
$main_content = $this->renderCache->getCacheableRenderArray($main_content) + [
'#title' => isset($main_content['#title']) ? $main_content['#title'] : NULL
];
diff --git a/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php
index a91b14b..76153bd 100644
--- a/core/lib/Drupal/Core/Render/Renderer.php
+++ b/core/lib/Drupal/Core/Render/Renderer.php
@@ -89,16 +89,27 @@ public function __construct(ControllerResolverInterface $controller_resolver, Th
* {@inheritdoc}
*/
public function renderRoot(&$elements) {
- return $this->render($elements, TRUE);
+ if (isset(static::$stack)) {
+ throw new \LogicException('A stray renderRoot() invocation is causing bubbling of attached assets to break.');
+ }
+ static::$stack = new \SplStack();
+ $output = $this->render($elements, TRUE);
+ $this->resetStack();
+
+ return $output;
}
/**
* {@inheritdoc}
+ *
+ * @todo Rename to ::renderInIsolation()
*/
- public function renderPlain(&$elements) {
+ public function renderPlain(&$elements, $is_root_call = TRUE) {
$current_stack = static::$stack;
- $this->resetStack();
- $output = $this->renderRoot($elements);
+
+ static::$stack = new \SplStack();
+ $output = $this->render($elements, $is_root_call);
+
static::$stack = $current_stack;
return $output;
}
@@ -186,7 +197,7 @@ protected function doRender(&$elements, $is_root_call = FALSE) {
}
if (!isset(static::$stack)) {
- static::$stack = new \SplStack();
+ throw new \LogicException("Render Stack is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain() / renderRoot() or #pre_render pattern instead.");
}
static::$stack->push(new BubbleableMetadata());
diff --git a/core/modules/block/src/Tests/BlockViewBuilderTest.php b/core/modules/block/src/Tests/BlockViewBuilderTest.php
index 7a7aa64..ccb53e4 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 renderer.
+ *
+ * @var \Drupal\Core\Render\RendererInterface
+ */
+ 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->renderRoot($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->renderRoot($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 test the render cache.
$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->renderRoot($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->renderRoot($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->renderRoot($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->renderRoot($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 test the render cache.
$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->renderRoot($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->renderRoot($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 rendering.');
+ $this->assertIdentical($this->renderer->renderRoot($build), 'Hiya!
');
$this->assertTrue(isset($build['#prefix']) && $build['#prefix'] === 'Hiya!
', 'A cached block without content is altered.');
// Restore the previous request method.
diff --git a/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php b/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php
index 582d832..fe2c789 100644
--- a/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php
+++ b/core/modules/block_content/src/Tests/BlockContentCacheTagsTest.php
@@ -84,7 +84,7 @@ public function testBlock() {
// Drupal\Core\Render\Renderer.
$request_stack = $this->container->get('request_stack');
$request_stack->push(new Request());
- $this->container->get('renderer')->render($build);
+ $this->container->get('renderer')->renderRoot($build);
$request_stack->pop();
// Expected keys, contexts, and tags for the block.
diff --git a/core/modules/book/src/BookOutline.php b/core/modules/book/src/BookOutline.php
index 484fd2c..c4b4533 100644
--- a/core/modules/book/src/BookOutline.php
+++ b/core/modules/book/src/BookOutline.php
@@ -126,8 +126,7 @@ public function childrenLinks(array $book_link) {
}
if ($children) {
- $elements = $this->bookManager->bookTreeOutput($children);
- return drupal_render($elements);
+ return $this->bookManager->bookTreeOutput($children);
}
return '';
}
diff --git a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
index 949c8e5..0e237b1 100644
--- a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
+++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php
@@ -13,6 +13,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Render\Element;
+use Drupal\Core\Render\RendererInterface;
use Drupal\editor\Plugin\EditorBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\editor\Entity\Editor as EditorEntity;
@@ -56,6 +57,13 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
protected $ckeditorPluginManager;
/**
+ * The renderer.
+ *
+ * @var \Drupal\Core\Render\RendererInterface
+ */
+ protected $renderer;
+
+ /**
* Constructs a Drupal\Component\Plugin\PluginBase object.
*
* @param array $configuration
@@ -70,12 +78,15 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
* The module handler to invoke hooks on.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
+ * @param \Drupal\Core\Render\RendererInterface $renderer
+ * The renderer.
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->ckeditorPluginManager = $ckeditor_plugin_manager;
$this->moduleHandler = $module_handler;
$this->languageManager = $language_manager;
+ $this->renderer = $renderer;
}
/**
@@ -88,7 +99,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_definition,
$container->get('plugin.manager.ckeditor.plugin'),
$container->get('module_handler'),
- $container->get('language_manager')
+ $container->get('language_manager'),
+ $container->get('renderer')
);
}
@@ -145,7 +157,7 @@ public function settingsForm(array $form, FormStateInterface $form_state, Editor
'library' => array('ckeditor/drupal.ckeditor.admin'),
'drupalSettings' => [
'ckeditor' => [
- 'toolbarAdmin' => drupal_render($ckeditor_settings_toolbar),
+ 'toolbarAdmin' => $this->renderer->renderPlain($ckeditor_settings_toolbar),
],
],
),
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 319067d..8bcac2c 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -462,7 +462,7 @@ function comment_node_update_index(EntityInterface $node, $langcode) {
}
}
}
- return drupal_render($build);
+ return \Drupal::service('renderer')->renderPlain($build);
}
/**
diff --git a/core/modules/comment/src/Form/CommentAdminOverview.php b/core/modules/comment/src/Form/CommentAdminOverview.php
index 008e0bb..19354ff 100644
--- a/core/modules/comment/src/Form/CommentAdminOverview.php
+++ b/core/modules/comment/src/Form/CommentAdminOverview.php
@@ -204,7 +204,9 @@ public function buildForm(array $form, FormStateInterface $form_state, $type = '
'#url' => $comment_permalink,
),
),
- 'author' => drupal_render($username),
+ 'author' => array(
+ 'data' => $username,
+ ),
'posted_in' => array(
'data' => array(
'#type' => 'link',
diff --git a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
index 342765f..8e7bf27 100644
--- a/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
+++ b/core/modules/comment/src/Tests/CommentDefaultFormatterCacheTagsTest.php
@@ -57,6 +57,9 @@ protected function setUp() {
* Tests the bubbling of cache tags.
*/
public function testCacheTags() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
// Create the entity that will be commented upon.
$commented_entity = entity_create('entity_test', array('name' => $this->randomMachineName()));
$commented_entity->save();
@@ -65,11 +68,16 @@ public function testCacheTags() {
$build = \Drupal::entityManager()
->getViewBuilder('entity_test')
->view($commented_entity);
- drupal_render($build);
+ $renderer->renderRoot($build);
$expected_cache_tags = array(
'entity_test_view',
'entity_test:' . $commented_entity->id(),
'comment_list',
+ 'config:core.entity_form_display.comment.comment.default',
+ 'config:field.field.comment.comment.comment_body',
+ 'config:field.field.entity_test.entity_test.comment',
+ 'config:field.storage.comment.comment_body',
+ 'config:user.settings',
);
sort($expected_cache_tags);
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags before it has comments.');
@@ -102,7 +110,7 @@ public function testCacheTags() {
$build = \Drupal::entityManager()
->getViewBuilder('entity_test')
->view($commented_entity);
- drupal_render($build);
+ $renderer->renderRoot($build);
$expected_cache_tags = array(
'entity_test_view',
'entity_test:' . $commented_entity->id(),
@@ -112,6 +120,11 @@ public function testCacheTags() {
'config:filter.format.plain_text',
'user_view',
'user:2',
+ 'config:core.entity_form_display.comment.comment.default',
+ 'config:field.field.comment.comment.comment_body',
+ 'config:field.field.entity_test.entity_test.comment',
+ 'config:field.storage.comment.comment_body',
+ 'config:user.settings',
);
sort($expected_cache_tags);
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags when it has comments.');
diff --git a/core/modules/config/src/Form/ConfigSync.php b/core/modules/config/src/Form/ConfigSync.php
index 2c71254..7f240e3 100644
--- a/core/modules/config/src/Form/ConfigSync.php
+++ b/core/modules/config/src/Form/ConfigSync.php
@@ -21,6 +21,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Config\StorageComparer;
+use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Url;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -101,6 +102,13 @@ class ConfigSync extends FormBase {
protected $moduleInstaller;
/**
+ * The renderer.
+ *
+ * @var \Drupal\Core\Render\RendererInterface
+ */
+ protected $renderer;
+
+ /**
* Constructs the object.
*
* @param \Drupal\Core\Config\StorageInterface $staging_storage
@@ -123,8 +131,10 @@ class ConfigSync extends FormBase {
* The module installer.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
+ * @param \Drupal\Core\Render\RendererInterface
+ * The renderer.
*/
- public function __construct(StorageInterface $staging_storage, StorageInterface $active_storage, StorageInterface $snapshot_storage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler) {
+ public function __construct(StorageInterface $staging_storage, StorageInterface $active_storage, StorageInterface $snapshot_storage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, RendererInterface $renderer) {
$this->stagingStorage = $staging_storage;
$this->activeStorage = $active_storage;
$this->snapshotStorage = $snapshot_storage;
@@ -135,6 +145,7 @@ public function __construct(StorageInterface $staging_storage, StorageInterface
$this->moduleHandler = $module_handler;
$this->moduleInstaller = $module_installer;
$this->themeHandler = $theme_handler;
+ $this->renderer = $renderer;
}
/**
@@ -151,7 +162,8 @@ public static function create(ContainerInterface $container) {
$container->get('config.typed'),
$container->get('module_handler'),
$container->get('module_installer'),
- $container->get('theme_handler')
+ $container->get('theme_handler'),
+ $container->get('renderer')
);
}
@@ -209,7 +221,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#theme' => 'item_list',
'#items' => $change_list,
);
- $change_list_html = drupal_render($change_list_render);
+ $change_list_html = $this->renderer->renderPlain($change_list_render);
drupal_set_message($this->t('The following items in your active configuration have changes since the last import that may be lost on the next import. !changes', array('!changes' => $change_list_html)), 'warning');
}
}
diff --git a/core/modules/contact/src/MessageViewBuilder.php b/core/modules/contact/src/MessageViewBuilder.php
index 5b94582..a086f7a 100644
--- a/core/modules/contact/src/MessageViewBuilder.php
+++ b/core/modules/contact/src/MessageViewBuilder.php
@@ -65,9 +65,9 @@ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = N
$build[$key]['#label_display'] = 'hidden';
}
}
- $build = array(
- '#markup' => MailFormatHelper::htmlToText(drupal_render($build)),
- );
+ $build['#post_render'][] = function ($html, array $elements) {
+ return MailFormatHelper::htmlToText($html);
+ };
}
return $build;
}
diff --git a/core/modules/contextual/src/ContextualController.php b/core/modules/contextual/src/ContextualController.php
index aeee4a6..975113d 100644
--- a/core/modules/contextual/src/ContextualController.php
+++ b/core/modules/contextual/src/ContextualController.php
@@ -44,7 +44,7 @@ public function render(Request $request) {
'#type' => 'contextual_links',
'#contextual_links' => _contextual_id_to_links($id),
);
- $rendered[$id] = drupal_render($element);
+ $rendered[$id] = $this->container->get('renderer')->renderRoot($element);
}
return new JsonResponse($rendered);
diff --git a/core/modules/datetime/src/Tests/DateTimeFieldTest.php b/core/modules/datetime/src/Tests/DateTimeFieldTest.php
index f3fcae1..c85f71f 100644
--- a/core/modules/datetime/src/Tests/DateTimeFieldTest.php
+++ b/core/modules/datetime/src/Tests/DateTimeFieldTest.php
@@ -490,7 +490,7 @@ protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) {
$entity = entity_load('entity_test', $id);
$display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
$build = $display->build($entity);
- $output = drupal_render($build);
+ $output = \Drupal::service('renderer')->renderRoot($build);
$this->setRawContent($output);
$this->verbose($output);
}
diff --git a/core/modules/field/field.module b/core/modules/field/field.module
index 88ccff9..d09049e 100644
--- a/core/modules/field/field.module
+++ b/core/modules/field/field.module
@@ -121,7 +121,7 @@ function field_help($route_name, RouteMatchInterface $route_match) {
'#theme' => 'item_list',
'#items' => $items,
);
- $output .= drupal_render($item_list);
+ $output .= \Drupal::service('renderer')->renderPlain($item_list);
$output .= '';
}
diff --git a/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php b/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php
index 28f6334..432fe92 100644
--- a/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php
+++ b/core/modules/field/src/Tests/Boolean/BooleanFieldTest.php
@@ -114,7 +114,7 @@ function testBooleanField() {
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
- $this->setRawContent(drupal_render($content));
+ $this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertRaw('
' . $on . '
');
// Test if we can change the on label.
diff --git a/core/modules/field/src/Tests/Email/EmailFieldTest.php b/core/modules/field/src/Tests/Email/EmailFieldTest.php
index 169d067..b916ed0 100644
--- a/core/modules/field/src/Tests/Email/EmailFieldTest.php
+++ b/core/modules/field/src/Tests/Email/EmailFieldTest.php
@@ -102,7 +102,7 @@ function testEmailField() {
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
- $this->setRawContent(drupal_render($content));
+ $this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertLinkByHref('mailto:test@example.com');
}
diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
index 52fdc08..6f04ba2 100644
--- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
+++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php
@@ -179,6 +179,8 @@ public function testIdFormatter() {
* Tests the entity formatter.
*/
public function testEntityFormatter() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$formatter = 'entity_reference_entity_view';
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
@@ -196,7 +198,7 @@ public function testEntityFormatter() {
';
- drupal_render($build[0]);
+ $renderer->renderRoot($build[0]);
$this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field_1 . $expected_rendered_body_field_1, sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$expected_cache_tags = Cache::mergeTags(
\Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTags(),
@@ -206,7 +208,7 @@ public function testEntityFormatter() {
$this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter)));
// Test the second field item.
- drupal_render($build[1]);
+ $renderer->renderRoot($build[1]);
$this->assertEqual($build[1]['#markup'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
}
@@ -214,6 +216,8 @@ public function testEntityFormatter() {
* Tests the label formatter.
*/
public function testLabelFormatter() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$formatter = 'entity_reference_label';
// The 'link' settings is TRUE by default.
@@ -237,7 +241,7 @@ public function testLabelFormatter() {
'tags' => $this->referencedEntity->getCacheTags(),
),
);
- $this->assertEqual(drupal_render($build[0]), drupal_render($expected_item_1), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
+ $this->assertEqual($renderer->renderRoot($build[0]), $renderer->renderRoot($expected_item_1), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual(CacheableMetadata::createFromRenderArray($build[0]), CacheableMetadata::createFromRenderArray($expected_item_1));
// The second referenced entity is "autocreated", therefore not saved and
diff --git a/core/modules/field/src/Tests/String/StringFieldTest.php b/core/modules/field/src/Tests/String/StringFieldTest.php
index a097ec5..4eedca8 100644
--- a/core/modules/field/src/Tests/String/StringFieldTest.php
+++ b/core/modules/field/src/Tests/String/StringFieldTest.php
@@ -97,7 +97,7 @@ function _testTextfieldWidgets($field_type, $widget_type) {
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
- $this->setRawContent(drupal_render($content));
+ $this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertText($value, 'Filtered tags are not displayed');
}
}
diff --git a/core/modules/field_ui/src/Tests/ManageDisplayTest.php b/core/modules/field_ui/src/Tests/ManageDisplayTest.php
index 25294c4..04a353f 100644
--- a/core/modules/field_ui/src/Tests/ManageDisplayTest.php
+++ b/core/modules/field_ui/src/Tests/ManageDisplayTest.php
@@ -454,7 +454,7 @@ function assertNodeViewTextHelper(EntityInterface $node, $view_mode, $text, $mes
// Render a cloned node, so that we do not alter the original.
$clone = clone $node;
$element = node_view($clone, $view_mode);
- $output = drupal_render($element);
+ $output = \Drupal::service('renderer')->renderRoot($element);
$this->verbose(t('Rendered node - view mode: @view_mode', array('@view_mode' => $view_mode)) . '
'. $output);
// Assign content so that WebTestBase functions can be used.
diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc
index 782ae70..f09760f 100644
--- a/core/modules/file/file.field.inc
+++ b/core/modules/file/file.field.inc
@@ -72,7 +72,7 @@ function template_preprocess_file_widget_multiple(&$variables) {
// Save the uploading row for last.
if (empty($widget['#files'])) {
$widget['#title'] = $element['#file_upload_title'];
- $widget['#description'] = drupal_render($element['#file_upload_description']);
+ $widget['#description'] = \Drupal::service('renderer')->renderPlain($element['#file_upload_description']);
continue;
}
diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
index da48f74..6cc3fd6 100644
--- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
+++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
@@ -267,7 +267,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
'#upload_validators' => $element['#upload_validators'],
'#cardinality' => $cardinality,
);
- $element['#description'] = drupal_render($file_upload_help);
+ $element['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
$element['#multiple'] = $cardinality != 1 ? TRUE : FALSE;
if ($cardinality != 1 && $cardinality != -1) {
$element['#element_validate'] = array(array(get_class($this), 'validateMultipleCount'));
diff --git a/core/modules/file/src/Tests/FileFieldDisplayTest.php b/core/modules/file/src/Tests/FileFieldDisplayTest.php
index 900374c..12193e3 100644
--- a/core/modules/file/src/Tests/FileFieldDisplayTest.php
+++ b/core/modules/file/src/Tests/FileFieldDisplayTest.php
@@ -62,7 +62,7 @@ function testNodeDisplay() {
'#theme' => 'file_link',
'#file' => $node_file,
);
- $default_output = drupal_render($file_link);
+ $default_output = \Drupal::service('renderer')->renderRoot($file_link);
$this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.');
// Turn the "display" option off and check that the file is no longer displayed.
diff --git a/core/modules/file/src/Tests/FileItemTest.php b/core/modules/file/src/Tests/FileItemTest.php
index 2c5c11c..140b00c 100644
--- a/core/modules/file/src/Tests/FileItemTest.php
+++ b/core/modules/file/src/Tests/FileItemTest.php
@@ -117,7 +117,7 @@ public function testFileItem() {
$entity->file_test = array('entity' => $file3);
$uri = $file3->getFileUri();
$output = entity_view($entity, 'default');
- drupal_render($output);
+ \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/forum/src/Tests/ForumTest.php b/core/modules/forum/src/Tests/ForumTest.php
index 9440179..1e9eac9 100644
--- a/core/modules/forum/src/Tests/ForumTest.php
+++ b/core/modules/forum/src/Tests/ForumTest.php
@@ -602,7 +602,7 @@ private function verifyForums(EntityInterface $node, $admin, $response = 200) {
'#theme' => 'breadcrumb',
'#links' => $breadcrumb_build,
);
- $this->assertRaw(drupal_render($breadcrumb), 'Breadcrumbs were displayed');
+ $this->assertRaw(\Drupal::service('renderer')->renderRoot($breadcrumb), 'Breadcrumbs were displayed');
// View forum edit node.
$this->drupalGet('node/' . $node->id() . '/edit');
@@ -662,7 +662,7 @@ private function verifyForumView($forum, $parent = NULL) {
'#theme' => 'breadcrumb',
'#links' => $breadcrumb_build,
);
- $this->assertRaw(drupal_render($breadcrumb), 'Breadcrumbs were displayed');
+ $this->assertRaw(\Drupal::service('renderer')->renderRoot($breadcrumb), 'Breadcrumbs were displayed');
}
/**
diff --git a/core/modules/history/src/Tests/Views/HistoryTimestampTest.php b/core/modules/history/src/Tests/Views/HistoryTimestampTest.php
index ed9a3bd..44f67f9 100644
--- a/core/modules/history/src/Tests/Views/HistoryTimestampTest.php
+++ b/core/modules/history/src/Tests/Views/HistoryTimestampTest.php
@@ -70,7 +70,7 @@ public function testHandlers() {
$this->executeView($view);
$this->assertEqual(count($view->result), 2);
$output = $view->preview();
- $this->setRawContent(drupal_render($output));
+ $this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
$result = $this->xpath('//span[@class=:class]', array(':class' => 'marker'));
$this->assertEqual(count($result), 1, 'Just one node is marked as new');
diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
index ad18e4c..f202293 100644
--- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
+++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php
@@ -98,7 +98,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f
// If there's only one field, return it as delta 0.
if (empty($elements[0]['#default_value']['fids'])) {
$file_upload_help['#description'] = $this->fieldFilterXss($this->fieldDefinition->getDescription());
- $elements[0]['#description'] = drupal_render($file_upload_help);
+ $elements[0]['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
}
}
else {
diff --git a/core/modules/image/src/Tests/ImageDimensionsTest.php b/core/modules/image/src/Tests/ImageDimensionsTest.php
index 2db7e24..6d97142 100644
--- a/core/modules/image/src/Tests/ImageDimensionsTest.php
+++ b/core/modules/image/src/Tests/ImageDimensionsTest.php
@@ -243,7 +243,7 @@ function testImageDimensions() {
* re-rendered each time.
*/
protected function getImageTag($variables) {
- return str_replace("\n", NULL, drupal_render($variables));
+ return str_replace("\n", NULL, \Drupal::service('renderer')->renderRoot($variables));
}
}
diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php
index 74b07ed..73063b9 100644
--- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php
+++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php
@@ -48,6 +48,8 @@ function testImageFieldFormattersPrivate() {
* Test image formatters on node display.
*/
function _testImageFieldFormatters($scheme) {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$field_name = strtolower($this->randomMachineName());
$field_settings = array('alt_field_required' => 0);
@@ -103,7 +105,7 @@ function _testImageFieldFormatters($scheme) {
'#height' => 20,
'#alt' => $alt,
);
- $default_output = str_replace("\n", NULL, drupal_render($image));
+ $default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
$this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.');
// Test the image linked to file formatter.
@@ -122,7 +124,7 @@ function _testImageFieldFormatters($scheme) {
'#height' => 20,
'#alt' => $alt,
);
- $default_output = '' . drupal_render($image) . '';
+ $default_output = '' . $renderer->renderRoot($image) . '';
$this->drupalGet('node/' . $nid);
$this->assertCacheTag($file->getCacheTags()[0]);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
@@ -188,7 +190,7 @@ function _testImageFieldFormatters($scheme) {
'#style_name' => 'thumbnail',
'#alt' => $alt,
);
- $default_output = drupal_render($image_style);
+ $default_output = $renderer->renderRoot($image_style);
$this->drupalGet('node/' . $nid);
$image_style = ImageStyle::load('thumbnail');
$this->assertCacheTag($image_style->getCacheTags()[0]);
@@ -206,6 +208,8 @@ function _testImageFieldFormatters($scheme) {
* Tests for image field settings.
*/
function testImageFieldSettings() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$test_image = current($this->drupalGetTestFiles('image'));
list(, $test_image_extension) = explode('.', $test_image->filename);
@@ -258,7 +262,7 @@ function testImageFieldSettings() {
'#height' => 20,
'#style_name' => 'medium',
);
- $default_output = drupal_render($image_style);
+ $default_output = $renderer->renderRoot($image_style);
$this->assertRaw($default_output, "Preview image is displayed using 'medium' style.");
// Add alt/title fields to the image and verify that they are displayed.
@@ -275,7 +279,7 @@ function testImageFieldSettings() {
$field_name . '[0][title]' => $image['#title'],
);
$this->drupalPostForm('node/' . $nid . '/edit', $edit, t('Save and keep published'));
- $default_output = str_replace("\n", NULL, drupal_render($image));
+ $default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
$this->assertRaw($default_output, 'Image displayed using user supplied alt and title attributes.');
// Verify that alt/title longer than allowed results in a validation error.
@@ -325,6 +329,9 @@ function testImageFieldSettings() {
* Test use of a default image with an image field.
*/
function testImageFieldDefaultImage() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
$node_storage = $this->container->get('entity.manager')->getStorage('node');
// Create a new image field.
$field_name = strtolower($this->randomMachineName());
@@ -364,7 +371,7 @@ function testImageFieldDefaultImage() {
'#width' => 40,
'#height' => 20,
);
- $default_output = str_replace("\n", NULL, drupal_render($image));
+ $default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
$this->drupalGet('node/' . $node->id());
$this->assertCacheTag($file->getCacheTags()[0]);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
@@ -388,7 +395,7 @@ function testImageFieldDefaultImage() {
'#height' => 20,
'#alt' => $alt,
);
- $image_output = str_replace("\n", NULL, drupal_render($image));
+ $image_output = str_replace("\n", NULL, $renderer->renderRoot($image));
$this->drupalGet('node/' . $nid);
$this->assertCacheTag($file->getCacheTags()[0]);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
@@ -436,7 +443,7 @@ function testImageFieldDefaultImage() {
'#width' => 40,
'#height' => 20,
);
- $default_output = str_replace("\n", NULL, drupal_render($image));
+ $default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
$this->drupalGet('node/' . $node->id());
$this->assertCacheTag($file->getCacheTags()[0]);
$cache_tags_header = $this->drupalGetHeader('X-Drupal-Cache-Tags');
diff --git a/core/modules/image/src/Tests/ImageThemeFunctionTest.php b/core/modules/image/src/Tests/ImageThemeFunctionTest.php
index a67c2eb..9a2046b 100644
--- a/core/modules/image/src/Tests/ImageThemeFunctionTest.php
+++ b/core/modules/image/src/Tests/ImageThemeFunctionTest.php
@@ -63,6 +63,9 @@ protected function setUp() {
* Tests usage of the image field formatters.
*/
function testImageFormatterTheme() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
// Create an image.
$files = $this->drupalGetTestFiles('image');
$file = reset($files);
@@ -92,7 +95,7 @@ function testImageFormatterTheme() {
// Test using theme_image_formatter() with a NULL value for the alt option.
$element = $base_element;
- $this->setRawContent(drupal_render($element));
+ $this->setRawContent($renderer->renderRoot($element));
$elements = $this->xpath('//a[@href=:path]/img[@class="image-style-test" and @src=:url and @width=:width and @height=:height]', array(':path' => base_path() . $path, ':url' => $url, ':width' => $image->getWidth(), ':height' => $image->getHeight()));
$this->assertEqual(count($elements), 1, 'theme_image_formatter() correctly renders with a NULL value for the alt option.');
@@ -100,7 +103,7 @@ function testImageFormatterTheme() {
// link options.
$element = $base_element;
$element['#item']->alt = '';
- $this->setRawContent(drupal_render($element));
+ $this->setRawContent($renderer->renderRoot($element));
$elements = $this->xpath('//a[@href=:path]/img[@class="image-style-test" and @src=:url and @width=:width and @height=:height and @alt=""]', array(':path' => base_path() . $path, ':url' => $url, ':width' => $image->getWidth(), ':height' => $image->getHeight()));
$this->assertEqual(count($elements), 1, 'theme_image_formatter() correctly renders without title, alt, or path options.');
@@ -108,7 +111,7 @@ function testImageFormatterTheme() {
$fragment = $this->randomMachineName();
$element = $base_element;
$element['#url'] = Url::fromRoute('', [], ['fragment' => $fragment]);
- $this->setRawContent(drupal_render($element));
+ $this->setRawContent($renderer->renderRoot($element));
$elements = $this->xpath('//a[@href=:fragment]/img[@class="image-style-test" and @src=:url and @width=:width and @height=:height and @alt=""]', array(
':fragment' => '#' . $fragment,
':url' => $url,
@@ -122,6 +125,9 @@ function testImageFormatterTheme() {
* Tests usage of the image style theme function.
*/
function testImageStyleTheme() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
// Create an image.
$files = $this->drupalGetTestFiles('image');
$file = reset($files);
@@ -140,14 +146,14 @@ function testImageStyleTheme() {
);
$element = $base_element;
- $this->setRawContent(drupal_render($element));
+ $this->setRawContent($renderer->renderRoot($element));
$elements = $this->xpath('//img[@class="image-style-image-test" and @src=:url and @alt=""]', array(':url' => $url));
$this->assertEqual(count($elements), 1, 'theme_image_style() renders an image correctly.');
// Test using theme_image_style() with a NULL value for the alt option.
$element = $base_element;
$element['#alt'] = NULL;
- $this->setRawContent(drupal_render($element));
+ $this->setRawContent($renderer->renderRoot($element));
$elements = $this->xpath('//img[@class="image-style-image-test" and @src=:url]', array(':url' => $url));
$this->assertEqual(count($elements), 1, 'theme_image_style() renders an image correctly with a NULL value for the alt option.');
}
@@ -156,6 +162,9 @@ function testImageStyleTheme() {
* Tests image alt attribute functionality.
*/
function testImageAltFunctionality() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
// Test using alt directly with alt attribute.
$image_with_alt_property = array(
'#theme' => 'image',
@@ -167,7 +176,7 @@ function testImageAltFunctionality() {
'#attributes' => array('class' => 'image-with-regular-alt', 'id' => 'my-img'),
);
- $this->setRawContent(drupal_render($image_with_alt_property));
+ $this->setRawContent($renderer->renderRoot($image_with_alt_property));
$elements = $this->xpath('//img[contains(@class, class) and contains(@alt, :alt)]', array(":class" => "image-with-regular-alt", ":alt" => "Regular alt"));
$this->assertEqual(count($elements), 1, 'Regular alt displays correctly');
@@ -185,7 +194,7 @@ function testImageAltFunctionality() {
),
);
- $this->setRawContent(drupal_render($image_with_alt_attribute_alt_attribute));
+ $this->setRawContent($renderer->renderRoot($image_with_alt_attribute_alt_attribute));
$elements = $this->xpath('//img[contains(@class, class) and contains(@alt, :alt)]', array(":class" => "image-with-attribute-alt", ":alt" => "Attribute alt"));
$this->assertEqual(count($elements), 1, 'Attribute alt displays correctly');
@@ -204,7 +213,7 @@ function testImageAltFunctionality() {
),
);
- $this->setRawContent(drupal_render($image_with_alt_attribute_both));
+ $this->setRawContent($renderer->renderRoot($image_with_alt_attribute_both));
$elements = $this->xpath('//img[contains(@class, class) and contains(@alt, :alt)]', array(":class" => "image-with-attribute-alt", ":alt" => "Attribute alt"));
$this->assertEqual(count($elements), 1, 'Attribute alt overrides alt property if both set.');
}
diff --git a/core/modules/link/src/Tests/LinkFieldTest.php b/core/modules/link/src/Tests/LinkFieldTest.php
index a1cdc65..0279ed1 100644
--- a/core/modules/link/src/Tests/LinkFieldTest.php
+++ b/core/modules/link/src/Tests/LinkFieldTest.php
@@ -588,7 +588,7 @@ protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) {
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), $view_mode);
$content = $display->build($entity);
- $output = drupal_render($content);
+ $output = \Drupal::service('renderer')->renderRoot($content);
$this->setRawContent($output);
$this->verbose($output);
}
diff --git a/core/modules/node/src/Tests/SummaryLengthTest.php b/core/modules/node/src/Tests/SummaryLengthTest.php
index 0c34eb0..3eb44df 100644
--- a/core/modules/node/src/Tests/SummaryLengthTest.php
+++ b/core/modules/node/src/Tests/SummaryLengthTest.php
@@ -19,6 +19,9 @@ class SummaryLengthTest extends NodeTestBase {
* Tests the node summary length functionality.
*/
public function testSummaryLength() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
// Create a node to view.
$settings = array(
'body' => array(array('value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam vitae arcu at leo cursus laoreet. Curabitur dui tortor, adipiscing malesuada tempor in, bibendum ac diam. Cras non tellus a libero pellentesque condimentum. What is a Drupalism? Suspendisse ac lacus libero. Ut non est vel nisl faucibus interdum nec sed leo. Pellentesque sem risus, vulputate eu semper eget, auctor in libero. Ut fermentum est vitae metus convallis scelerisque. Phasellus pellentesque rhoncus tellus, eu dignissim purus posuere id. Quisque eu fringilla ligula. Morbi ullamcorper, lorem et mattis egestas, tortor neque pretium velit, eget eleifend odio turpis eu purus. Donec vitae metus quis leo pretium tincidunt a pulvinar sem. Morbi adipiscing laoreet mauris vel placerat. Nullam elementum, nisl sit amet scelerisque malesuada, dolor nunc hendrerit quam, eu ultrices erat est in orci. Curabitur feugiat egestas nisl sed accumsan.')),
@@ -30,7 +33,7 @@ public function testSummaryLength() {
// Render the node as a teaser.
$content = $this->drupalBuildEntityView($node, 'teaser');
$this->assertTrue(strlen($content['body'][0]['#markup']) < 600, 'Teaser is less than 600 characters long.');
- $this->setRawContent(drupal_render($content));
+ $this->setRawContent($renderer->renderRoot($content));
// The string 'What is a Drupalism?' is between the 200th and 600th
// characters of the node body, so it should be included if the summary is
// 600 characters long.
@@ -48,7 +51,7 @@ public function testSummaryLength() {
// 200 characters in length and so does not include 'What is a Drupalism?'.
$content = $this->drupalBuildEntityView($node, 'teaser');
$this->assertTrue(strlen($content['body'][0]['#markup']) < 200, 'Teaser is less than 200 characters long.');
- $this->setRawContent(drupal_render($content));
+ $this->setRawContent($renderer->renderRoot($content));
$this->assertText($node->label());
$this->assertNoRaw($expected);
}
diff --git a/core/modules/node/src/Tests/Views/RowPluginTest.php b/core/modules/node/src/Tests/Views/RowPluginTest.php
index a2f6585..4da5ad9 100644
--- a/core/modules/node/src/Tests/Views/RowPluginTest.php
+++ b/core/modules/node/src/Tests/Views/RowPluginTest.php
@@ -64,6 +64,8 @@ protected function setUp() {
* Tests the node row plugin.
*/
public function testRowPlugin() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$view = Views::getView('test_node_row_plugin');
$view->initDisplay();
$view->setDisplay('page_1');
@@ -72,7 +74,7 @@ public function testRowPlugin() {
// Test with view_mode full.
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
foreach ($this->nodes as $node) {
$this->assertFalse(strpos($output, $node->body->summary) !== FALSE, 'Make sure the teaser appears in the output of the view.');
$this->assertTrue(strpos($output, $node->body->value) !== FALSE, 'Make sure the full text appears in the output of the view.');
@@ -81,7 +83,7 @@ public function testRowPlugin() {
// Test with teasers.
$view->rowPlugin->options['view_mode'] = 'teaser';
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
foreach ($this->nodes as $node) {
$this->assertTrue(strpos($output, $node->body->summary) !== FALSE, 'Make sure the teaser appears in the output of the view.');
$this->assertFalse(strpos($output, $node->body->value) !== FALSE, 'Make sure the full text does not appears in the output of the view if teaser is set as viewmode.');
diff --git a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php
index 1747b19..22cdb45 100644
--- a/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php
+++ b/core/modules/quickedit/src/Tests/QuickEditLoadingTest.php
@@ -422,7 +422,7 @@ public function testDisplayOptions() {
'label' => 'inline',
);
$build = $node->body->view($display_settings);
- $output = drupal_render($build);
+ $output = \Drupal::service('renderer')->renderRoot($build);
$this->assertFalse(strpos($output, 'data-quickedit-field-id'), 'data-quickedit-field-id attribute not added when rendering field using dynamic display options.');
}
diff --git a/core/modules/rdf/src/Tests/EntityReferenceFieldAttributesTest.php b/core/modules/rdf/src/Tests/EntityReferenceFieldAttributesTest.php
index 44f8d2f..52c4e86 100644
--- a/core/modules/rdf/src/Tests/EntityReferenceFieldAttributesTest.php
+++ b/core/modules/rdf/src/Tests/EntityReferenceFieldAttributesTest.php
@@ -103,7 +103,7 @@ function testNodeTeaser() {
// Render the node.
$node_render_array = entity_view_multiple(array($node), 'teaser');
- $html = drupal_render($node_render_array);
+ $html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parse the teaser.
$parser = new \EasyRdf_Parser_Rdfa();
diff --git a/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php b/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php
index 6161326..cb8f584 100644
--- a/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php
+++ b/core/modules/rdf/src/Tests/Field/FieldRdfaTestBase.php
@@ -93,7 +93,7 @@ protected function assertFormatterRdfa($formatter, $property, $expected_rdf_valu
->setComponent($this->fieldName, $formatter)
->save();
$build = entity_view($this->entity, 'default');
- $output = drupal_render($build);
+ $output = \Drupal::service('renderer')->renderRoot($build);
$graph = new \EasyRdf_Graph($this->uri, $output, 'rdfa');
$this->setRawContent($output);
diff --git a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php
index e6aea38..ead4c2b 100644
--- a/core/modules/rdf/src/Tests/FileFieldAttributesTest.php
+++ b/core/modules/rdf/src/Tests/FileFieldAttributesTest.php
@@ -81,7 +81,7 @@ protected function setUp() {
function testNodeTeaser() {
// Render the teaser.
$node_render_array = entity_view_multiple(array($this->node), 'teaser');
- $html = drupal_render($node_render_array);
+ $html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parses front page where the node is displayed in its teaser form.
$parser = new \EasyRdf_Parser_Rdfa();
diff --git a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php
index 4ae8f0b..c5b482a 100644
--- a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php
+++ b/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php
@@ -87,7 +87,7 @@ function testNodeTeaser() {
// Render the teaser.
$node_render_array = node_view($this->node, 'teaser');
- $html = drupal_render($node_render_array);
+ $html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parse the teaser.
$parser = new \EasyRdf_Parser_Rdfa();
diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php
index ccc09be..facd063 100644
--- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php
+++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php
@@ -163,6 +163,8 @@ protected function addTestImageStyleMappings($empty_styles = FALSE) {
* Defaults to false.
*/
protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles = FALSE) {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$field_name = Unicode::strtolower($this->randomMachineName());
$this->createImageField($field_name, 'article', array('uri_scheme' => $scheme));
@@ -186,7 +188,7 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles =
'#height' => 240,
'#alt' => $alt,
);
- $default_output = str_replace("\n", NULL, drupal_render($image));
+ $default_output = str_replace("\n", NULL, $renderer->renderRoot($image));
$this->assertRaw($default_output, 'Default formatter displaying correctly on full node view.');
// Use the responsive image formatter linked to file formatter.
@@ -282,7 +284,7 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles =
// The image.html.twig template has a newline after the tag but
// responsive-image.html.twig doesn't have one after the fallback image, so
// we remove it here.
- $default_output = trim(drupal_render($fallback_image));
+ $default_output = trim($renderer->renderRoot($fallback_image));
$this->assertRaw($default_output, 'Image style large formatter displaying correctly on full node view.');
if ($scheme == 'private') {
diff --git a/core/modules/simpletest/src/Form/SimpletestResultsForm.php b/core/modules/simpletest/src/Form/SimpletestResultsForm.php
index d41654f..a1b97ba 100644
--- a/core/modules/simpletest/src/Form/SimpletestResultsForm.php
+++ b/core/modules/simpletest/src/Form/SimpletestResultsForm.php
@@ -94,10 +94,10 @@ protected static function buildStatusImageMap() {
'#alt' => 'Debug',
);
return array(
- 'pass' => drupal_render($image_pass),
- 'fail' => drupal_render($image_fail),
- 'exception' => drupal_render($image_exception),
- 'debug' => drupal_render($image_debug),
+ 'pass' => $image_pass,
+ 'fail' => $image_fail,
+ 'exception' => $image_exception,
+ 'debug' => $image_debug,
);
}
@@ -205,7 +205,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
// Under normal circumstances, a form object's submitForm() should never be
// called directly, FormBuilder::submitForm() should be called instead.
// However, it calls $form_state->setProgrammed(), which disables the Batch API.
- $simpletest_test_form = new SimpletestTestForm();
+ $simpletest_test_form = SimpletestTestForm::create(\Drupal::getContainer());
$simpletest_test_form->buildForm($form_execute, $form_state_execute);
$simpletest_test_form->submitForm($form_execute, $form_state_execute);
if ($redirect = $form_state_execute->getRedirect()) {
diff --git a/core/modules/simpletest/src/Form/SimpletestTestForm.php b/core/modules/simpletest/src/Form/SimpletestTestForm.php
index 92c8a54..f6d0367 100644
--- a/core/modules/simpletest/src/Form/SimpletestTestForm.php
+++ b/core/modules/simpletest/src/Form/SimpletestTestForm.php
@@ -11,6 +11,8 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Render\RendererInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* List tests arranged in groups that can be selected and run.
@@ -18,6 +20,32 @@
class SimpletestTestForm extends FormBase {
/**
+ * The renderer.
+ *
+ * @var \Drupal\Core\Render\RendererInterface
+ */
+ protected $renderer;
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('renderer')
+ );
+ }
+
+ /**
+ * Constructs a new SimpletestTestForm.
+ *
+ * @param \Drupal\Core\Render\RendererInterface $renderer
+ * The renderer.
+ */
+ public function __construct(RendererInterface $renderer) {
+ $this->renderer = $renderer;
+ }
+
+ /**
* {@inheritdoc}
*/
public function getFormId() {
@@ -99,8 +127,8 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#suffix' => '(' . $this->t('Collapse') . ')',
);
$form['tests']['#attached']['drupalSettings']['simpleTest']['images'] = [
- drupal_render($image_collapsed),
- drupal_render($image_extended),
+ $this->renderer->renderPlain($image_collapsed),
+ $this->renderer->renderPlain($image_extended),
];
// Generate the list of tests arranged by group.
diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
index 2e8a8c2..b22ece7 100644
--- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
+++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php
@@ -284,6 +284,8 @@ function testEnableModulesFixedList() {
* Tests that _theme() works right after loading a module.
*/
function testEnableModulesTheme() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$original_element = $element = array(
'#type' => 'container',
'#markup' => 'Foo',
@@ -291,11 +293,11 @@ function testEnableModulesTheme() {
);
$this->enableModules(array('system'));
// _theme() throws an exception if modules are not loaded yet.
- $this->assertTrue(drupal_render($element));
+ $this->assertTrue($renderer->renderRoot($element));
$element = $original_element;
$this->disableModules(array('entity_test'));
- $this->assertTrue(drupal_render($element));
+ $this->assertTrue($renderer->renderRoot($element));
}
/**
diff --git a/core/modules/system/src/Tests/Ajax/DialogTest.php b/core/modules/system/src/Tests/Ajax/DialogTest.php
index 23c9403..28873df 100644
--- a/core/modules/system/src/Tests/Ajax/DialogTest.php
+++ b/core/modules/system/src/Tests/Ajax/DialogTest.php
@@ -35,7 +35,7 @@ public function testDialog() {
// Set up variables for this test.
$dialog_renderable = \Drupal\ajax_test\Controller\AjaxTestController::dialogContents();
- $dialog_contents = drupal_render($dialog_renderable);
+ $dialog_contents = \Drupal::service('renderer')->renderRoot($dialog_renderable);
$modal_expected_response = array(
'command' => 'openDialog',
'selector' => '#drupal-modal',
diff --git a/core/modules/system/src/Tests/Common/AddFeedTest.php b/core/modules/system/src/Tests/Common/AddFeedTest.php
index 4378279..fbb9cc2 100644
--- a/core/modules/system/src/Tests/Common/AddFeedTest.php
+++ b/core/modules/system/src/Tests/Common/AddFeedTest.php
@@ -90,7 +90,7 @@ function testFeedIconEscaping() {
'#url' => 'node',
'#title' => '<>&"\'',
);
- $text = drupal_render($variables);
+ $text = \Drupal::service('renderer')->renderRoot($variables);
preg_match('/title="(.*?)"/', $text, $matches);
$this->assertEqual($matches[1], 'Subscribe to &"'', 'feed_icon template escapes reserved HTML characters.');
}
diff --git a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
index 3aa3cec..a18fd77 100644
--- a/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
+++ b/core/modules/system/src/Tests/Common/RenderElementTypesTest.php
@@ -43,7 +43,7 @@ protected function setUp() {
* Assertion message.
*/
protected function assertElements(array $elements, $expected_html, $message) {
- $actual_html = drupal_render($elements);
+ $actual_html = \Drupal::service('renderer')->renderRoot($elements);
$out = '';
$out .= '' . SafeMarkup::checkPlain($expected_html) . ' | ';
@@ -198,7 +198,7 @@ function testMoreLink() {
);
foreach($elements as $element) {
- $xml = new \SimpleXMLElement(drupal_render($element['value']));
+ $xml = new \SimpleXMLElement(\Drupal::service('renderer')->renderRoot($element['value']));
$result = $xml->xpath($element['expected']);
$this->assertTrue($result, '"' . $element['name'] . '" input rendered correctly by drupal_render().');
}
@@ -229,7 +229,7 @@ function testSystemCompactLink() {
);
foreach ($elements as $element) {
- $xml = new \SimpleXMLElement(drupal_render($element['value']));
+ $xml = new \SimpleXMLElement(\Drupal::service('renderer')->renderRoot($element['value']));
$result = $xml->xpath($element['expected']);
$this->assertTrue($result, '"' . $element['name'] . '" is rendered correctly by drupal_render().');
}
@@ -245,7 +245,7 @@ function testSystemCompactLink() {
'expected' => '//div[@class="compact-link"]/a[contains(@href, "admin/compact?") and text()="Show descriptions"]',
);
- $xml = new \SimpleXMLElement(drupal_render($element['value']));
+ $xml = new \SimpleXMLElement(\Drupal::service('renderer')->renderRoot($element['value']));
$result = $xml->xpath($element['expected']);
$this->assertTrue($result, '"' . $element['name'] . '" is rendered correctly by drupal_render().');
}
diff --git a/core/modules/system/src/Tests/Common/RenderTest.php b/core/modules/system/src/Tests/Common/RenderTest.php
index 66354a5..7ae448a 100644
--- a/core/modules/system/src/Tests/Common/RenderTest.php
+++ b/core/modules/system/src/Tests/Common/RenderTest.php
@@ -39,7 +39,7 @@ function testDrupalRenderThemePreprocessAttached() {
'#markup' => 'Kittens!',
],
];
- drupal_render($test_element);
+ \Drupal::service('renderer')->renderRoot($test_element);
$expected_attached = [
'library' => [
diff --git a/core/modules/system/src/Tests/Common/UrlTest.php b/core/modules/system/src/Tests/Common/UrlTest.php
index c095676..93f0503 100644
--- a/core/modules/system/src/Tests/Common/UrlTest.php
+++ b/core/modules/system/src/Tests/Common/UrlTest.php
@@ -63,7 +63,7 @@ function testLinkCacheability() {
'#options' => $options,
'#url' => Url::fromUri($uri),
];
- drupal_render($link);
+ \Drupal::service('renderer')->renderRoot($link);
$this->pass($title);
$this->assertEqual($expected_cacheability, $link['#cache']);
}
@@ -73,6 +73,9 @@ function testLinkCacheability() {
* Tests that default and custom attributes are handled correctly on links.
*/
function testLinkAttributes() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
// Test that hreflang is added when a link has a known language.
$language = new Language(array('id' => 'fr', 'name' => 'French'));
$hreflang_link = array(
@@ -90,10 +93,10 @@ function testLinkAttributes() {
$hreflang_override_link = $hreflang_link;
$hreflang_override_link['#options']['attributes']['hreflang'] = 'foo';
- $rendered = drupal_render($hreflang_link);
+ $rendered = $renderer->renderRoot($hreflang_link);
$this->assertTrue($this->hasAttribute('hreflang', $rendered, $langcode), format_string('hreflang attribute with value @langcode is present on a rendered link when langcode is provided in the render array.', array('@langcode' => $langcode)));
- $rendered = drupal_render($hreflang_override_link);
+ $rendered = $renderer->renderRoot($hreflang_override_link);
$this->assertTrue($this->hasAttribute('hreflang', $rendered, 'foo'), format_string('hreflang attribute with value @hreflang is present on a rendered link when @hreflang is provided in the render array.', array('@hreflang' => 'foo')));
// Test the active class in links produced by _l() and #type 'link'.
@@ -149,7 +152,7 @@ function testLinkAttributes() {
),
),
);
- $link_theme = drupal_render($type_link);
+ $link_theme = $renderer->renderRoot($type_link);
$this->assertTrue($this->hasAttribute('class', $link_theme, $class_theme), format_string('Custom class @class is present on link when requested by #type', array('@class' => $class_theme)));
}
@@ -157,6 +160,9 @@ function testLinkAttributes() {
* Tests that link functions support render arrays as 'text'.
*/
function testLinkRenderArrayText() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
// Build a link with _l() for reference.
$l = \Drupal::l('foo', Url::fromUri('https://www.drupal.org'));
@@ -171,7 +177,7 @@ function testLinkRenderArrayText() {
'#title' => 'foo',
'#url' => Url::fromUri('https://www.drupal.org'),
);
- $type_link_plain = drupal_render($type_link_plain_array);
+ $type_link_plain = $renderer->renderRoot($type_link_plain_array);
$this->assertEqual($type_link_plain, $l);
// Build a themed link with renderable 'text'.
@@ -180,7 +186,7 @@ function testLinkRenderArrayText() {
'#title' => array('#markup' => 'foo'),
'#url' => Url::fromUri('https://www.drupal.org'),
);
- $type_link_nested = drupal_render($type_link_nested_array);
+ $type_link_nested = $renderer->renderRoot($type_link_nested_array);
$this->assertEqual($type_link_nested, $l);
}
diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
index 7d513eb..138794f 100644
--- a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
@@ -559,6 +559,9 @@ function testLanguageFallback() {
* The entity type to run the tests with.
*/
protected function doTestLanguageFallback($entity_type) {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
$current_langcode = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
$this->langcodes[] = $current_langcode;
@@ -609,16 +612,16 @@ protected function doTestLanguageFallback($entity_type) {
// Get an view builder.
$controller = $this->entityManager->getViewBuilder($entity_type);
$entity2_build = $controller->view($entity2);
- $entity2_output = drupal_render($entity2_build);
+ $entity2_output = $renderer->renderRoot($entity2_build);
$translation = $this->entityManager->getTranslationFromContext($entity2, $default_langcode);
$translation_build = $controller->view($translation);
- $translation_output = drupal_render($translation_build);
+ $translation_output = $renderer->renderRoot($translation_build);
$this->assertIdentical($entity2_output, $translation_output, 'When the entity has no translation no fallback is applied.');
// Checks that entity translations are rendered properly.
$controller = $this->entityManager->getViewBuilder($entity_type);
$build = $controller->view($entity);
- drupal_render($build);
+ $renderer->renderRoot($build);
$this->assertEqual($build['label']['#markup'], $values[$current_langcode]['name'], 'By default the entity is rendered in the current language.');
$langcodes = array_combine($this->langcodes, $this->langcodes);
@@ -630,7 +633,7 @@ protected function doTestLanguageFallback($entity_type) {
// Unset the #cache key so that a fresh render is produced with each pass,
// making the renderable array keys available to compare.
unset($build['#cache']);
- drupal_render($build);
+ $renderer->renderRoot($build);
$this->assertEqual($build['label']['#markup'], $values[$expected]['name'], 'The entity is rendered in the expected language.');
}
}
diff --git a/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php b/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php
index 333dcda..a7aa63d 100644
--- a/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityViewBuilderTest.php
@@ -46,6 +46,8 @@ protected function setUp() {
* Tests entity render cache handling.
*/
public function testEntityViewBuilderCache() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$cache_contexts_manager = \Drupal::service("cache_contexts_manager");
// Force a request via GET so we can get drupal_render() cache working.
@@ -72,7 +74,7 @@ public function testEntityViewBuilderCache() {
$build['#markup'] = 'entity_render_test';
// Test that a cache entry is created.
- drupal_render($build);
+ $renderer->renderRoot($build);
$this->assertTrue($this->container->get('cache.' . $bin)->get($cid), 'The entity render element has been cached.');
// Re-save the entity and check that the cache entry has been deleted.
@@ -82,7 +84,7 @@ public function testEntityViewBuilderCache() {
// Rebuild the render array (creating a new cache entry in the process) and
// delete the entity to check the cache entry is deleted.
unset($build['#printed']);
- drupal_render($build);
+ $renderer->renderRoot($build);
$this->assertTrue($this->container->get('cache.' . $bin)->get($cid), 'The entity render element has been cached.');
$entity_test->delete();
$this->assertFalse($this->container->get('cache.' . $bin)->get($cid), 'The entity render cache has been cleared when the entity was deleted.');
@@ -95,6 +97,8 @@ public function testEntityViewBuilderCache() {
* Tests entity render cache with references.
*/
public function testEntityViewBuilderCacheWithReferences() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$cache_contexts_manager = \Drupal::service("cache_contexts_manager");
// Force a request via GET so we can get drupal_render() cache working.
@@ -120,7 +124,7 @@ public function testEntityViewBuilderCacheWithReferences() {
// Mock the build array to not require the theme registry.
unset($build['#theme']);
$build['#markup'] = 'entity_render_test';
- drupal_render($build);
+ $renderer->renderRoot($build);
// Test that a cache entry was created for the referenced entity.
$this->assertTrue($this->container->get('cache.' . $bin_reference)->get($cid_reference), 'The entity render element for the referenced entity has been cached.');
@@ -139,7 +143,7 @@ public function testEntityViewBuilderCacheWithReferences() {
// Mock the build array to not require the theme registry.
unset($build['#theme']);
$build['#markup'] = 'entity_render_test';
- drupal_render($build);
+ $renderer->renderRoot($build);
// Test that a cache entry is created.
$this->assertTrue($this->container->get('cache.' . $bin)->get($cid), 'The entity render element has been cached.');
@@ -180,6 +184,9 @@ public function testEntityViewBuilderCacheToggling() {
* Tests weighting of display components.
*/
public function testEntityViewBuilderWeight() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
// Set a weight for the label component.
entity_get_display('entity_test', 'entity_test', 'full')
->setComponent('label', array('weight' => 20))
@@ -188,7 +195,7 @@ public function testEntityViewBuilderWeight() {
// Create and build a test entity.
$entity_test = $this->createTestEntity('entity_test');
$view = $this->container->get('entity.manager')->getViewBuilder('entity_test')->view($entity_test, 'full');
- drupal_render($view);
+ $renderer->renderRoot($view);
// Check that the weight is respected.
$this->assertEqual($view['label']['#weight'], 20, 'The weight of a display component is respected.');
diff --git a/core/modules/system/src/Tests/Form/CheckboxTest.php b/core/modules/system/src/Tests/Form/CheckboxTest.php
index da53a79..13b7d07 100644
--- a/core/modules/system/src/Tests/Form/CheckboxTest.php
+++ b/core/modules/system/src/Tests/Form/CheckboxTest.php
@@ -33,7 +33,7 @@ function testFormCheckbox() {
// @see \Drupal\Core\Render\Element\Checkbox::processCheckbox().
foreach (array('0', '', 1, '1', 'foobar', '1foobar') as $return_value) {
$form_array = \Drupal::formBuilder()->getForm('\Drupal\form_test\Form\FormTestCheckboxTypeJugglingForm', $default_value, $return_value);
- $form = drupal_render($form_array);
+ $form = \Drupal::service('renderer')->renderRoot($form_array);
if ($default_value === TRUE) {
$checked = TRUE;
}
diff --git a/core/modules/system/src/Tests/Form/FormTest.php b/core/modules/system/src/Tests/Form/FormTest.php
index be1fc26..910000b 100644
--- a/core/modules/system/src/Tests/Form/FormTest.php
+++ b/core/modules/system/src/Tests/Form/FormTest.php
@@ -124,7 +124,7 @@ function testRequiredFields() {
// when you try to render them like this, so we ignore those for
// testing the required marker.
// @todo Fix this work-around (https://www.drupal.org/node/588438).
- $form_output = ($type == 'radios') ? '' : drupal_render($form);
+ $form_output = ($type == 'radios') ? '' : \Drupal::service('renderer')->renderRoot($form);
if ($required) {
// Make sure we have a form error for this element.
$this->assertTrue(isset($errors[$element]), "Check empty($key) '$type' field '$element'");
diff --git a/core/modules/system/src/Tests/Theme/FunctionsTest.php b/core/modules/system/src/Tests/Theme/FunctionsTest.php
index a9a3dae..0ed135d 100644
--- a/core/modules/system/src/Tests/Theme/FunctionsTest.php
+++ b/core/modules/system/src/Tests/Theme/FunctionsTest.php
@@ -347,7 +347,7 @@ function testDrupalPreRenderLinks() {
// thing. We expect a single with appropriate links contained within
// it.
$render_array = $base_array;
- $html = drupal_render($render_array);
+ $html = \Drupal::service('renderer')->renderRoot($render_array);
$dom = new \DOMDocument();
$dom->loadHTML($html);
$this->assertEqual($dom->getElementsByTagName('ul')->length, 1, 'One "ul" tag found in the rendered HTML.');
@@ -363,8 +363,8 @@ function testDrupalPreRenderLinks() {
// sure we get two separate 's with the appropriate links contained
// within each.
$render_array = $base_array;
- $child_html = drupal_render($render_array['first_child']);
- $parent_html = drupal_render($render_array);
+ $child_html = \Drupal::service('renderer')->renderRoot($render_array['first_child']);
+ $parent_html = \Drupal::service('renderer')->renderRoot($render_array);
// First check the child HTML.
$dom = new \DOMDocument();
$dom->loadHTML($child_html);
diff --git a/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php b/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php
index 4b6d528..1b330d0 100644
--- a/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php
+++ b/core/modules/system/src/Tests/Theme/TwigDebugMarkupTest.php
@@ -27,6 +27,8 @@ class TwigDebugMarkupTest extends WebTestBase {
* Tests debug markup added to Twig template output.
*/
function testTwigDebugMarkup() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$extension = twig_extension();
\Drupal::service('theme_handler')->install(array('test_theme'));
$this->config('system.theme')->set('default', 'test_theme')->save();
@@ -46,7 +48,7 @@ function testTwigDebugMarkup() {
// Create a node and test different features of the debug markup.
$node = $this->drupalCreateNode();
$build = node_view($node);
- $output = drupal_render($build);
+ $output = $renderer->renderRoot($build);
$this->assertTrue(strpos($output, '') !== FALSE, 'Twig debug markup found in theme output when debug is enabled.');
$this->setRawContent($output);
$this->assertTrue(strpos($output, "THEME HOOK: 'node'") !== FALSE, 'Theme call information found.');
@@ -59,7 +61,7 @@ function testTwigDebugMarkup() {
// debug markup are correct.
$node2 = $this->drupalCreateNode();
$build = node_view($node2);
- $output = drupal_render($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.');
// Create another node and make sure the template suggestions shown in the
@@ -67,7 +69,7 @@ function testTwigDebugMarkup() {
$node3 = $this->drupalCreateNode();
$build = array('#theme' => 'node__foo__bar');
$build += node_view($node3);
- $output = drupal_render($build);
+ $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.');
@@ -79,7 +81,7 @@ function testTwigDebugMarkup() {
$this->resetAll();
$build = node_view($node);
- $output = drupal_render($build);
+ $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/system/src/Tests/Theme/TwigEnvironmentTest.php b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php
index f113ead..b5450df 100644
--- a/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php
+++ b/core/modules/system/src/Tests/Theme/TwigEnvironmentTest.php
@@ -30,6 +30,8 @@ class TwigEnvironmentTest extends KernelTestBase {
* Tests inline templates.
*/
public function testInlineTemplate() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
/** @var \Drupal\Core\Template\TwigEnvironment $environment */
$environment = \Drupal::service('twig');
$this->assertEqual($environment->renderInline('test-no-context'), 'test-no-context');
@@ -42,7 +44,7 @@ public function testInlineTemplate() {
'#template' => 'test-with-context {{ unsafe_content }}',
'#context' => array('unsafe_content' => $unsafe_string),
);
- $this->assertEqual(drupal_render($element), 'test-with-context ' . SafeMarkup::checkPlain($unsafe_string));
+ $this->assertEqual($renderer->renderRoot($element), 'test-with-context ' . SafeMarkup::checkPlain($unsafe_string));
// Enable twig_auto_reload and twig_debug.
$settings = Settings::getAll();
@@ -61,8 +63,8 @@ public function testInlineTemplate() {
);
$element_copy = $element;
// Render it twice so that twig caching is triggered.
- $this->assertEqual(drupal_render($element), 'test-with-context muuh');
- $this->assertEqual(drupal_render($element_copy), 'test-with-context muuh');
+ $this->assertEqual($renderer->renderRoot($element), 'test-with-context muuh');
+ $this->assertEqual($renderer->renderRoot($element_copy), 'test-with-context muuh');
}
/**
diff --git a/core/modules/system/src/Tests/Theme/TwigFilterTest.php b/core/modules/system/src/Tests/Theme/TwigFilterTest.php
index 3aa2d54..2adc8c9 100644
--- a/core/modules/system/src/Tests/Theme/TwigFilterTest.php
+++ b/core/modules/system/src/Tests/Theme/TwigFilterTest.php
@@ -41,7 +41,7 @@ public function testTwigWithoutFilter() {
'class' => array('red', 'green', 'blue'),
),
);
- $rendered = drupal_render($filter_test);
+ $rendered = \Drupal::service('renderer')->renderRoot($filter_test);
$this->setRawContent($rendered);
$elements = array(
diff --git a/core/modules/system/src/Tests/Theme/TwigNamespaceTest.php b/core/modules/system/src/Tests/Theme/TwigNamespaceTest.php
index 2b6f3c5..4065e84 100644
--- a/core/modules/system/src/Tests/Theme/TwigNamespaceTest.php
+++ b/core/modules/system/src/Tests/Theme/TwigNamespaceTest.php
@@ -58,7 +58,7 @@ public function testTemplateDiscovery() {
public function testTwigNamespaces() {
// Test twig @extends and @include in template files.
$test = array('#theme' => 'twig_namespace_test');
- $this->setRawContent(drupal_render($test));
+ $this->setRawContent(\Drupal::service('renderer')->renderRoot($test));
$this->assertText('This line is from twig_namespace_a/templates/test.html.twig');
$this->assertText('This line is from twig_namespace_b/templates/test.html.twig');
diff --git a/core/modules/system/src/Tests/Theme/TwigRawTest.php b/core/modules/system/src/Tests/Theme/TwigRawTest.php
index 5cec948..7ef605f 100644
--- a/core/modules/system/src/Tests/Theme/TwigRawTest.php
+++ b/core/modules/system/src/Tests/Theme/TwigRawTest.php
@@ -31,7 +31,7 @@ public function testAutoescapeRaw() {
'#theme' => 'twig_raw_test',
'#script' => '',
);
- $rendered = drupal_render($test);
+ $rendered = \Drupal::service('renderer')->renderRoot($test);
$this->setRawContent($rendered);
$this->assertRaw('');
}
@@ -48,7 +48,7 @@ public function testAutoescape() {
'#theme' => 'twig_autoescape_test',
'#script' => $script,
];
- $rendered = drupal_render($build);
+ $rendered = \Drupal::service('renderer')->renderRoot($build);
$this->setRawContent($rendered);
$this->assertEscaped($script);
}
diff --git a/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php b/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php
index 8d89b6e..6b43aa8 100644
--- a/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php
+++ b/core/modules/system/tests/modules/common_test/src/Controller/CommonTestController.php
@@ -77,8 +77,7 @@ public function jsAndCssQuerystring() {
),
),
);
- drupal_render($attached);
- return '';
+ return \Drupal::service('renderer')->renderRoot($attached);
}
/**
diff --git a/core/modules/text/src/Tests/Formatter/TextFormatterTest.php b/core/modules/text/src/Tests/Formatter/TextFormatterTest.php
index cae892e..324f2cf 100644
--- a/core/modules/text/src/Tests/Formatter/TextFormatterTest.php
+++ b/core/modules/text/src/Tests/Formatter/TextFormatterTest.php
@@ -90,7 +90,7 @@ public function testFormatters() {
foreach ($formatters as $formatter) {
// Verify the text field formatter's render array.
$build = $entity->get('formatted_text')->view(array('type' => $formatter));
- drupal_render($build[0]);
+ \Drupal::service('renderer')->renderRoot($build[0]);
$this->assertEqual($build[0]['#markup'], "Hello, world!
\n");
$this->assertEqual($build[0]['#cache']['tags'], FilterFormat::load('my_text_format')->getCacheTags(), format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', array('@formatter' => $formatter)));
}
diff --git a/core/modules/text/src/Tests/TextFieldTest.php b/core/modules/text/src/Tests/TextFieldTest.php
index 1507a02..37120c9 100644
--- a/core/modules/text/src/Tests/TextFieldTest.php
+++ b/core/modules/text/src/Tests/TextFieldTest.php
@@ -87,6 +87,9 @@ function testTextfieldWidgetsFormatted() {
* Helper function for testTextfieldWidgetsFormatted().
*/
function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
// Create a field.
$field_name = Unicode::strtolower($this->randomMachineName());
$field_storage = entity_create('field_storage_config', array(
@@ -138,7 +141,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
- $this->setRawContent(drupal_render($content));
+ $this->setRawContent($renderer->renderRoot($content));
$this->assertNoRaw($value, 'HTML tags are not displayed.');
$this->assertEscaped($value, 'Escaped HTML is displayed correctly.');
@@ -177,7 +180,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
- $this->setRawContent(drupal_render($content));
+ $this->setRawContent($renderer->renderRoot($content));
$this->assertRaw($value, 'Value is displayed unfiltered');
}
diff --git a/core/modules/views/src/Plugin/views/style/StylePluginBase.php b/core/modules/views/src/Plugin/views/style/StylePluginBase.php
index 8fa4617..af10867 100644
--- a/core/modules/views/src/Plugin/views/style/StylePluginBase.php
+++ b/core/modules/views/src/Plugin/views/style/StylePluginBase.php
@@ -678,7 +678,7 @@ protected function renderFields(array $result) {
'#cache_properties' => $field_ids,
];
$renderer->addCacheableDependency($data, $this->view->storage);
- $renderer->render($data);
+ $renderer->renderPlain($data);
// Extract field output from the render array and post process it.
$fields = $this->view->field;
diff --git a/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php b/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php
index 6a8a12d..1037f45 100644
--- a/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php
+++ b/core/modules/views/src/Tests/Entity/RowEntityRenderersTest.php
@@ -220,7 +220,7 @@ protected function assertTranslations($display, $renderer_id, array $expected, $
foreach ($expected as $index => $expected_output) {
if (!empty($view->result[$index])) {
$build = $view->rowPlugin->render($view->result[$index]);
- $output = drupal_render($build);
+ $output = \Drupal::service('renderer')->renderRoot($build);
$result = strpos($output, $expected_output) !== FALSE;
if (!$result) {
break;
diff --git a/core/modules/views/src/Tests/Handler/AreaEntityTest.php b/core/modules/views/src/Tests/Handler/AreaEntityTest.php
index 28d867f..f429770 100644
--- a/core/modules/views/src/Tests/Handler/AreaEntityTest.php
+++ b/core/modules/views/src/Tests/Handler/AreaEntityTest.php
@@ -122,6 +122,8 @@ public function testEntityArea() {
* The entities.
*/
public function doTestRender($entities) {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$view = Views::getView('test_entity_area');
$preview = $view->preview('default', [$entities[1]->id()]);
$this->setRawContent(\Drupal::service('renderer')->render($preview));
@@ -138,7 +140,7 @@ public function doTestRender($entities) {
$this->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
$preview = $view->preview('default', array($entities[1]->id()));
- $this->setRawContent(drupal_render($preview));
+ $this->setRawContent($renderer->renderRoot($preview));
$result = $this->xpath($header_xpath);
$this->assertTrue(strpos(trim((string) $result[0]), $entities[0]->label()) !== FALSE, 'The rendered entity appears in the header of the view.');
@@ -160,7 +162,7 @@ public function doTestRender($entities) {
$view->setHandler('default', 'header', 'entity_entity_test', $item);
$preview = $view->preview('default', array($entities[1]->id()));
- $this->setRawContent(drupal_render($preview));
+ $this->setRawContent($renderer->renderRoot($preview));
$view_class = 'js-view-dom-id-' . $view->dom_id;
$result = $this->xpath('//div[@class = "' . $view_class . '"]/div[1]');
$this->assertTrue(strpos(trim((string) $result[0]), $entities[0]->label()) !== FALSE, 'The rendered entity appears in the header of the view.');
@@ -169,7 +171,7 @@ public function doTestRender($entities) {
// Test entity access.
$view = Views::getView('test_entity_area');
$preview = $view->preview('default', array($entities[2]->id()));
- $this->setRawContent(drupal_render($preview));
+ $this->setRawContent($renderer->renderRoot($preview));
$view_class = 'js-view-dom-id-' . $view->dom_id;
$result = $this->xpath('//div[@class = "' . $view_class . '"]/div[3]');
$this->assertTrue(strpos($result[0], $entities[2]->label()) === FALSE, 'The rendered entity does not appear in the footer of the view.');
diff --git a/core/modules/views/src/Tests/Handler/AreaTest.php b/core/modules/views/src/Tests/Handler/AreaTest.php
index 385db71..49984a4 100644
--- a/core/modules/views/src/Tests/Handler/AreaTest.php
+++ b/core/modules/views/src/Tests/Handler/AreaTest.php
@@ -108,7 +108,7 @@ public function testRenderArea() {
// Check whether the strings exist in the output and are sanitized.
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $this->container->get('renderer')->renderRoot($output);
$this->assertTrue(strpos($output, Xss::filterAdmin($header_string)) !== FALSE, 'Views header exists in the output and is sanitized');
$this->assertTrue(strpos($output, Xss::filterAdmin($footer_string)) !== FALSE, 'Views footer exists in the output and is sanitized');
$this->assertTrue(strpos($output, Xss::filterAdmin($empty_string)) !== FALSE, 'Views empty exists in the output and is sanitized');
@@ -187,7 +187,7 @@ public function testRenderAreaToken() {
// Test we have the site:name token in the output.
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $this->container->get('renderer')->renderRoot($output);
$expected = \Drupal::token()->replace('[site:name]');
$this->assertTrue(strpos($output, $expected) !== FALSE);
}
diff --git a/core/modules/views/src/Tests/Handler/AreaTextTest.php b/core/modules/views/src/Tests/Handler/AreaTextTest.php
index 5387a6e..e37f2a2 100644
--- a/core/modules/views/src/Tests/Handler/AreaTextTest.php
+++ b/core/modules/views/src/Tests/Handler/AreaTextTest.php
@@ -35,6 +35,8 @@ protected function setUp() {
}
public function testAreaText() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$view = Views::getView('test_view');
$view->setDisplay();
@@ -56,18 +58,18 @@ public function testAreaText() {
$view->display_handler->handlers['header']['area']->options['content']['format'] = $this->randomString();
$build = $view->display_handler->handlers['header']['area']->render();
- $this->assertEqual('', drupal_render($build), 'Nonexistent format should return empty markup.');
+ $this->assertEqual('', $renderer->renderRoot($build), 'Nonexistent format should return empty markup.');
$view->display_handler->handlers['header']['area']->options['content']['format'] = filter_default_format();
$build = $view->display_handler->handlers['header']['area']->render();
- $this->assertEqual(check_markup($string), drupal_render($build), 'Existent format should return something');
+ $this->assertEqual(check_markup($string), $renderer->renderRoot($build), 'Existent format should return something');
// Empty results, and it shouldn't be displayed .
$this->assertEqual(array(), $view->display_handler->handlers['header']['area']->render(TRUE), 'No result should lead to no header');
// Empty results, and it should be displayed.
$view->display_handler->handlers['header']['area']->options['empty'] = TRUE;
$build = $view->display_handler->handlers['header']['area']->render(TRUE);
- $this->assertEqual(check_markup($string), drupal_render($build), 'No result, but empty enabled lead to a full header');
+ $this->assertEqual(check_markup($string), $renderer->renderRoot($build), 'No result, but empty enabled lead to a full header');
}
}
diff --git a/core/modules/views/src/Tests/Handler/AreaViewTest.php b/core/modules/views/src/Tests/Handler/AreaViewTest.php
index dc03fa9..858e4fa 100644
--- a/core/modules/views/src/Tests/Handler/AreaViewTest.php
+++ b/core/modules/views/src/Tests/Handler/AreaViewTest.php
@@ -36,6 +36,8 @@ class AreaViewTest extends ViewUnitTestBase {
* Tests the view area handler.
*/
public function testViewArea() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$view = Views::getView('test_area_view');
// Tests \Drupal\views\Plugin\views\area\View::calculateDependencies().
@@ -43,14 +45,14 @@ public function testViewArea() {
$this->executeView($view);
$output = $view->render();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, 'js-view-dom-id-' . $view->dom_id) !== FALSE, 'The test view is correctly embedded.');
$view->destroy();
$view->setArguments(array(27));
$this->executeView($view);
$output = $view->render();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, 'John') === FALSE, 'The test view is correctly embedded with inherited arguments.');
$this->assertTrue(strpos($output, 'George') !== FALSE, 'The test view is correctly embedded with inherited arguments.');
$view->destroy();
diff --git a/core/modules/views/src/Tests/Handler/FieldFieldAccessTestBase.php b/core/modules/views/src/Tests/Handler/FieldFieldAccessTestBase.php
index 5554a8a..09b397d 100644
--- a/core/modules/views/src/Tests/Handler/FieldFieldAccessTestBase.php
+++ b/core/modules/views/src/Tests/Handler/FieldFieldAccessTestBase.php
@@ -125,7 +125,7 @@ protected function assertFieldAccess($entity_type_id, $field_name, $field_conten
$account_switcher->switchTo($this->userWithAccess);
$executable = Views::getView($view_id);
$build = $executable->preview();
- $this->setRawContent($renderer->render($build));
+ $this->setRawContent($renderer->renderRoot($build));
$this->assertText($field_content);
$this->assertTrue(isset($executable->field[$field_name]));
@@ -133,7 +133,7 @@ protected function assertFieldAccess($entity_type_id, $field_name, $field_conten
$account_switcher->switchTo($this->userWithoutAccess);
$executable = Views::getView($view_id);
$build = $executable->preview();
- $this->setRawContent($renderer->render($build));
+ $this->setRawContent($renderer->renderRoot($build));
$this->assertNoText($field_content);
$this->assertFalse(isset($executable->field[$field_name]));
diff --git a/core/modules/views/src/Tests/Handler/FieldUnitTest.php b/core/modules/views/src/Tests/Handler/FieldUnitTest.php
index 7c319d4..f76e1ce 100644
--- a/core/modules/views/src/Tests/Handler/FieldUnitTest.php
+++ b/core/modules/views/src/Tests/Handler/FieldUnitTest.php
@@ -231,13 +231,15 @@ public function testFieldTokens() {
* Tests the exclude setting.
*/
public function testExclude() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$view = Views::getView('test_field_output');
$view->initHandlers();
// Hide the field and see whether it's rendered.
$view->field['name']->options['exclude'] = TRUE;
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
foreach ($this->dataSet() as $entry) {
$this->assertNotSubString($output, $entry['name']);
}
@@ -246,7 +248,7 @@ public function testExclude() {
$view->field['name']->options['exclude'] = FALSE;
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
foreach ($this->dataSet() as $entry) {
$this->assertSubString($output, $entry['name']);
}
diff --git a/core/modules/views/src/Tests/Handler/FieldWebTest.php b/core/modules/views/src/Tests/Handler/FieldWebTest.php
index 3fde585..45a1617 100644
--- a/core/modules/views/src/Tests/Handler/FieldWebTest.php
+++ b/core/modules/views/src/Tests/Handler/FieldWebTest.php
@@ -342,6 +342,8 @@ public function testAlterUrl() {
* Tests the field/label/wrapper classes.
*/
public function testFieldClasses() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$view = Views::getView('test_field_classes');
$view->initHandlers();
@@ -352,13 +354,13 @@ public function testFieldClasses() {
// Setup some kind of label by default.
$id_field->options['label'] = $this->randomMachineName();
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertFalse($this->xpathContent($output, '//div[contains(@class, :class)]', array(':class' => 'field-content')));
$this->assertFalse($this->xpathContent($output, '//div[contains(@class, :class)]', array(':class' => 'field-label')));
$id_field->options['element_default_classes'] = TRUE;
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
// Per default the label and the element of the field are spans.
$this->assertTrue($this->xpathContent($output, '//span[contains(@class, :class)]', array(':class' => 'field-content')));
$this->assertTrue($this->xpathContent($output, '//span[contains(@class, :class)]', array(':class' => 'views-label')));
@@ -374,13 +376,13 @@ public function testFieldClasses() {
// Set a custom wrapper element css class.
$id_field->options['element_wrapper_class'] = $random_class;
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertTrue($this->xpathContent($output, "//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
// Set no custom css class.
$id_field->options['element_wrapper_class'] = '';
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertFalse($this->xpathContent($output, "//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
$this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]/{$element_type}"));
}
@@ -394,13 +396,13 @@ public function testFieldClasses() {
// Set a custom label element css class.
$id_field->options['element_label_class'] = $random_class;
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
// Set no custom css class.
$id_field->options['element_label_class'] = '';
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertFalse($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
$this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//{$element_type}"));
}
@@ -414,13 +416,13 @@ public function testFieldClasses() {
// Set a custom label element css class.
$id_field->options['element_class'] = $random_class;
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
// Set no custom css class.
$id_field->options['element_class'] = '';
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertFalse($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}[contains(@class, :class)]", array(':class' => $random_class)));
$this->assertTrue($this->xpathContent($output, "//li[contains(@class, views-row)]//div[contains(@class, views-field)]//{$element_type}"));
}
diff --git a/core/modules/views/src/Tests/Plugin/DisplayTest.php b/core/modules/views/src/Tests/Plugin/DisplayTest.php
index 81bb1c2..0517063 100644
--- a/core/modules/views/src/Tests/Plugin/DisplayTest.php
+++ b/core/modules/views/src/Tests/Plugin/DisplayTest.php
@@ -52,6 +52,8 @@ protected function setUp() {
* @see \Drupal\views_test_data\Plugin\views\display\DisplayTest
*/
public function testDisplayPlugin() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$view = Views::getView('test_view');
// Add a new 'display_test' display and test it's there.
@@ -97,7 +99,7 @@ public function testDisplayPlugin() {
$this->assertIdentical($view->display_handler->getOption('test_option'), '');
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, '') !== FALSE, 'An empty value for test_option found in output.');
@@ -106,7 +108,7 @@ public function testDisplayPlugin() {
$view->save();
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
// Test we have our custom tag in the output of the view.
$this->assertTrue(strpos($output, 'Test option title
') !== FALSE, 'The test_option value found in display output title.');
@@ -166,6 +168,9 @@ public function testGetAttachedDisplays() {
* Tests the readmore functionality.
*/
public function testReadMore() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
if (!isset($this->options['validate']['type'])) {
return;
}
@@ -175,7 +180,7 @@ public function testReadMore() {
$this->executeView($view);
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->setRawContent($output);
$result = $this->xpath('//a[@class=:class]', array(':class' => 'more-link'));
@@ -185,7 +190,7 @@ public function testReadMore() {
// Test the renderMoreLink method directly. This could be directly unit
// tested.
$more_link = $view->display_handler->renderMoreLink();
- $more_link = drupal_render($more_link);
+ $more_link = $renderer->renderRoot($more_link);
$this->setRawContent($more_link);
$result = $this->xpath('//a[@class=:class]', array(':class' => 'more-link'));
$this->assertEqual($result[0]->attributes()->href, \Drupal::url('view.test_display_more.page_1'), 'The right more link is shown.');
@@ -201,7 +206,7 @@ public function testReadMore() {
$view->display_handler->setOption('use_more', 0);
$this->executeView($view);
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->setRawContent($output);
$result = $this->xpath('//a[@class=:class]', array(':class' => 'more-link'));
$this->assertTrue(empty($result), 'The more link is not shown.');
@@ -219,7 +224,7 @@ public function testReadMore() {
));
$this->executeView($view);
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->setRawContent($output);
$result = $this->xpath('//a[@class=:class]', array(':class' => 'more-link'));
$this->assertTrue(empty($result), 'The more link is not shown when view has more records.');
diff --git a/core/modules/views/src/Tests/Plugin/ExposedFormTest.php b/core/modules/views/src/Tests/Plugin/ExposedFormTest.php
index 7e58113..ffc9bbe 100644
--- a/core/modules/views/src/Tests/Plugin/ExposedFormTest.php
+++ b/core/modules/views/src/Tests/Plugin/ExposedFormTest.php
@@ -135,7 +135,7 @@ public function testExposedFormRender() {
$this->executeView($view);
$exposed_form = $view->display_handler->getPlugin('exposed_form');
$output = $exposed_form->renderExposedForm();
- $this->setRawContent(drupal_render($output));
+ $this->setRawContent(\Drupal::service('renderer')->renderRoot($output));
$this->assertFieldByXpath('//form/@id', $this->getExpectedExposedFormId($view), 'Expected form ID found.');
diff --git a/core/modules/views/src/Tests/Plugin/PagerTest.php b/core/modules/views/src/Tests/Plugin/PagerTest.php
index 15384c1..d9c1eec 100644
--- a/core/modules/views/src/Tests/Plugin/PagerTest.php
+++ b/core/modules/views/src/Tests/Plugin/PagerTest.php
@@ -280,7 +280,7 @@ public function testRenderNullPager() {
$view->setAjaxEnabled(TRUE);
$view->pager = NULL;
$output = $view->render();
- $output = drupal_render($output);
+ $output = \Drupal::service('renderer')->renderRoot($output);
$this->assertEqual(preg_match('/