' . $rendered;
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 70cbc5d..58426c9 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/AttachedAssetsTest.php b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
index 21dc6b2..a9701ff 100644
--- a/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
+++ b/core/modules/system/src/Tests/Common/AttachedAssetsTest.php
@@ -94,8 +94,8 @@ function testAddFiles() {
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css);
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_css = $this->renderer->render($css_render_array);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_css = $this->renderer->renderPlain($css_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
$query_string = $this->container->get('state')->get('system.css_js_query_string') ?: '0';
$this->assertNotIdentical(strpos($rendered_css, ''), FALSE, 'Rendering an external CSS file.');
$this->assertNotIdentical(strpos($rendered_js, ''), FALSE, 'Rendering an external JavaScript file.');
@@ -132,8 +132,8 @@ function testAddExternalFiles() {
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css);
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_css = $this->renderer->render($css_render_array);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_css = $this->renderer->renderPlain($css_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
$this->assertNotIdentical(strpos($rendered_css, ''), FALSE, 'Rendering an external CSS file.');
$this->assertNotIdentical(strpos($rendered_js, ''), FALSE, 'Rendering an external JavaScript file.');
}
@@ -147,7 +147,7 @@ function testAttributes() {
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
$expected_1 = '';
$expected_2 = '';
$this->assertNotIdentical(strpos($rendered_js, $expected_1), FALSE, 'Rendered external JavaScript with correct defer and random attributes.');
@@ -163,7 +163,7 @@ function testAggregatedAttributes() {
$js = $this->assetResolver->getJsAssets($assets, TRUE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
$expected_1 = '';
$expected_2 = '';
$this->assertNotIdentical(strpos($rendered_js, $expected_1), FALSE, 'Rendered external JavaScript with correct defer and random attributes.');
@@ -203,7 +203,7 @@ function testSettings() {
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
// Parse the generated drupalSettings '), FALSE, 'The JS asset in common_test/js-header appears in the header.');
$this->assertNotIdentical(strpos($rendered_js, '' . "\n";
$expected_2 = "\n" . '' . "\n";
@@ -287,7 +287,7 @@ function testVersionQueryString() {
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
$this->assertTrue(strpos($rendered_js, 'core/assets/vendor/backbone/backbone-min.js?v=1.1.2') > 0 && strpos($rendered_js, 'core/assets/vendor/domready/ready.min.js?v=1.0.8') > 0 , 'JavaScript version identifiers correctly appended to URLs');
}
@@ -315,7 +315,7 @@ function testRenderOrder() {
// Retrieve the rendered JavaScript and test against the regex.
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
$matches = array();
if (preg_match_all('/weight_([-0-9]+_[0-9]+)/', $rendered_js, $matches)) {
$result = $matches[1];
@@ -357,7 +357,7 @@ function testRenderOrder() {
// Retrieve the rendered CSS and test against the regex.
$css = $this->assetResolver->getCssAssets($assets, FALSE);
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css);
- $rendered_css = $this->renderer->render($css_render_array);
+ $rendered_css = $this->renderer->renderPlain($css_render_array);
$matches = array();
if (preg_match_all('/([a-z]+)_weight_([-0-9]+_[0-9]+)/', $rendered_css, $matches)) {
$result = $matches[0];
@@ -380,7 +380,7 @@ function testRenderDifferentWeight() {
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
$this->assertTrue(strpos($rendered_js, 'lighter.css') < strpos($rendered_js, 'first.js'), 'Lighter CSS assets are rendered first.');
$this->assertTrue(strpos($rendered_js, 'lighter.js') < strpos($rendered_js, 'first.js'), 'Lighter JavaScript assets are rendered first.');
$this->assertTrue(strpos($rendered_js, 'before-jquery.js') < strpos($rendered_js, 'core/assets/vendor/jquery/jquery.min.js'), 'Rendering a JavaScript file above jQuery.');
@@ -402,7 +402,7 @@ function testAlter() {
// takes place.
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
$this->assertTrue(strpos($rendered_js, 'simpletest.js') < strpos($rendered_js, 'core/misc/tableselect.js'), 'Altering JavaScript weight through the alter hook.');
}
@@ -423,7 +423,7 @@ function testLibraryAlter() {
$assets = AttachedAssets::createFromRenderArray($build);
$js = $this->assetResolver->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
$this->assertTrue(strpos($rendered_js, 'core/assets/vendor/jquery-form/jquery.form.min.js'), 'Altered library dependencies are added to the page.');
}
@@ -474,9 +474,9 @@ function testAddJsFileWithQueryString() {
$this->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2', $js), 'JavaScript file with query string is correctly added.');
$css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css);
- $rendered_css = $this->renderer->render($css_render_array);
+ $rendered_css = $this->renderer->renderPlain($css_render_array);
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
- $rendered_js = $this->renderer->render($js_render_array);
+ $rendered_js = $this->renderer->renderPlain($js_render_array);
$query_string = $this->container->get('state')->get('system.css_js_query_string') ?: '0';
$this->assertNotIdentical(strpos($rendered_css, ''), FALSE, 'CSS file with query string gets version query string correctly appended..');
$this->assertNotIdentical(strpos($rendered_js, ''), FALSE, 'JavaScript file with query string gets version query string correctly appended.');
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..c8e553b 100644
--- a/core/modules/system/src/Tests/Common/UrlTest.php
+++ b/core/modules/system/src/Tests/Common/UrlTest.php
@@ -9,6 +9,7 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Cache\Cache;
+use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Language\Language;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
@@ -57,13 +58,14 @@ function testLinkCacheability() {
foreach ($cases as $case) {
list($title, $uri, $options, $expected_cacheability) = $case;
+ $expected_cacheability['contexts'] = Cache::mergeContexts($expected_cacheability['contexts'], ['languages:language_interface', 'theme']);
$link = [
'#type' => 'link',
'#title' => $title,
'#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 +75,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 +95,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 +154,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 +162,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 +179,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 +188,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/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php b/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php
index d8f609a..86a0128 100644
--- a/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php
+++ b/core/modules/system/tests/modules/theme_test/src/EventSubscriber/ThemeTestSubscriber.php
@@ -7,6 +7,7 @@
namespace Drupal\theme_test\EventSubscriber;
+use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Url;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpKernel\KernelEvents;
@@ -33,12 +34,22 @@ class ThemeTestSubscriber implements EventSubscriberInterface {
protected $currentRouteMatch;
/**
+ * The renderer.
+ *
+ * @var \Drupal\Core\Render\RendererInterface
+ */
+ protected $renderer;
+
+ /**
* Constructs a new ThemeTestSubscriber.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $current_route_match
+ * @param \Drupal\Core\Render\RendererInterface $renderer
+ * The renderer.
*/
- public function __construct(RouteMatchInterface $current_route_match) {
+ public function __construct(RouteMatchInterface $current_route_match, RendererInterface $renderer) {
$this->currentRouteMatch = $current_route_match;
+ $this->renderer = $renderer;
}
/**
@@ -62,7 +73,7 @@ public function onRequest(GetResponseEvent $event) {
'#url' => Url::fromRoute('user.page'),
'#attributes' => array('title' => 'Themed output generated in a KernelEvents::REQUEST listener'),
);
- $GLOBALS['theme_test_output'] = drupal_render($more_link);
+ $GLOBALS['theme_test_output'] = $this->renderer->renderPlain($more_link);
}
}
diff --git a/core/modules/system/tests/modules/theme_test/theme_test.services.yml b/core/modules/system/tests/modules/theme_test/theme_test.services.yml
index add8b4c..482c219 100644
--- a/core/modules/system/tests/modules/theme_test/theme_test.services.yml
+++ b/core/modules/system/tests/modules/theme_test/theme_test.services.yml
@@ -1,7 +1,7 @@
services:
theme_test.subscriber:
class: Drupal\theme_test\EventSubscriber\ThemeTestSubscriber
- arguments: [@current_route_match]
+ arguments: [@current_route_match, @renderer]
tags:
- { name: event_subscriber }
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/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module
index bca08e8..af992d1 100644
--- a/core/modules/toolbar/toolbar.module
+++ b/core/modules/toolbar/toolbar.module
@@ -287,7 +287,7 @@ function toolbar_get_rendered_subtrees() {
$link = $element->link;
if ($element->subtree) {
$subtree = $menu_tree->build($element->subtree);
- $output = drupal_render($subtree);
+ $output = \Drupal::service('renderer')->renderPlain($subtree);
}
else {
$output = '';
diff --git a/core/modules/tour/tests/tour_test/src/Plugin/tour/tip/TipPluginImage.php b/core/modules/tour/tests/tour_test/src/Plugin/tour/tip/TipPluginImage.php
index 109c587..90a5a4f 100644
--- a/core/modules/tour/tests/tour_test/src/Plugin/tour/tip/TipPluginImage.php
+++ b/core/modules/tour/tests/tour_test/src/Plugin/tour/tip/TipPluginImage.php
@@ -40,14 +40,15 @@ class TipPluginImage extends TipPluginBase {
* {@inheritdoc}
*/
public function getOutput() {
- $image = array(
+ $prefix = '