'
diff --git a/core/modules/simpletest/src/Form/SimpletestResultsForm.php b/core/modules/simpletest/src/Form/SimpletestResultsForm.php
index d41654f..ea3447e 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()) {
@@ -318,7 +318,7 @@ public static function addResultForm(array &$form, array $results) {
$row[] = \Drupal::service('file_system')->basename(($assertion->file));
$row[] = $assertion->line;
$row[] = $assertion->function;
- $row[] = $image_status_map[$assertion->status];
+ $row[] = ['data' => $image_status_map[$assertion->status]];
$class = 'simpletest-' . $assertion->status;
if ($assertion->message_group == 'Debug') {
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/simpletest/src/Tests/SimpleTestTest.php b/core/modules/simpletest/src/Tests/SimpleTestTest.php
index 2514d9d..479ca39 100644
--- a/core/modules/simpletest/src/Tests/SimpleTestTest.php
+++ b/core/modules/simpletest/src/Tests/SimpleTestTest.php
@@ -24,7 +24,7 @@ class SimpleTestTest extends WebTestBase {
*
* @var array
*/
- public static $modules = array('simpletest', 'test_page_test');
+ public static $modules = ['simpletest'];
/**
* The results array that has been parsed by getTestResults().
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/Ajax/FrameworkTest.php b/core/modules/system/src/Tests/Ajax/FrameworkTest.php
index 52787c9..c7ccd8b 100644
--- a/core/modules/system/src/Tests/Ajax/FrameworkTest.php
+++ b/core/modules/system/src/Tests/Ajax/FrameworkTest.php
@@ -46,15 +46,15 @@ public function testOrder() {
$build['#attached']['library'][] = 'ajax_test/order-css-command';
$assets = AttachedAssets::createFromRenderArray($build);
$css_render_array = $css_collection_renderer->render($asset_resolver->getCssAssets($assets, FALSE));
- $expected_commands[1] = new AddCssCommand($renderer->render($css_render_array));
+ $expected_commands[1] = new AddCssCommand($renderer->renderRoot($css_render_array));
$build['#attached']['library'][] = 'ajax_test/order-header-js-command';
$build['#attached']['library'][] = 'ajax_test/order-footer-js-command';
$assets = AttachedAssets::createFromRenderArray($build);
list($js_assets_header, $js_assets_footer) = $asset_resolver->getJsAssets($assets, FALSE);
$js_header_render_array = $js_collection_renderer->render($js_assets_header);
$js_footer_render_array = $js_collection_renderer->render($js_assets_footer);
- $expected_commands[2] = new PrependCommand('head', $renderer->render($js_header_render_array));
- $expected_commands[3] = new AppendCommand('body', $renderer->render($js_footer_render_array));
+ $expected_commands[2] = new PrependCommand('head', $js_header_render_array);
+ $expected_commands[3] = new AppendCommand('body', $js_footer_render_array);
$expected_commands[4] = new HtmlCommand('body', 'Hello, world!');
// Load any page with at least one CSS file, at least one JavaScript file
@@ -123,14 +123,14 @@ public function testLazyLoad() {
$assets->setLibraries([$expected['library_1']])
->setAlreadyLoadedLibraries($original_libraries);
$css_render_array = $css_collection_renderer->render($asset_resolver->getCssAssets($assets, FALSE));
- $expected_css_html = $renderer->render($css_render_array);
+ $expected_css_html = $renderer->renderRoot($css_render_array);
$assets->setLibraries([$expected['library_2']])
->setAlreadyLoadedLibraries($original_libraries);
$js_assets = $asset_resolver->getJsAssets($assets, FALSE)[1];
unset($js_assets['drupalSettings']);
$js_render_array = $js_collection_renderer->render($js_assets);
- $expected_js_html = $renderer->render($js_render_array);
+ $expected_js_html = $renderer->renderRoot($js_render_array);
// Submit the AJAX request without triggering files getting added.
$commands = $this->drupalPostAjaxForm(NULL, array('add_files' => FALSE), array('op' => t('Submit')));
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..cf34843 100644
--- a/core/modules/system/src/Tests/Common/UrlTest.php
+++ b/core/modules/system/src/Tests/Common/UrlTest.php
@@ -9,7 +9,9 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Cache\Cache;
+use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Language\Language;
+use Drupal\Core\Render\RenderContext;
use Drupal\Core\Url;
use Drupal\simpletest\WebTestBase;
@@ -57,13 +59,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 +76,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 +96,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 +155,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,13 +163,18 @@ 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'));
// Test a renderable array passed to _l().
- $renderable_text = array('#markup' => 'foo');
- $l_renderable_text = \Drupal::l($renderable_text, Url::fromUri('https://www.drupal.org'));
- $this->assertEqual($l_renderable_text, $l);
+ $renderer->executeInRenderContext(new RenderContext(), function() use ($renderer, $l) {
+ $renderable_text = array('#markup' => 'foo');
+ $l_renderable_text = \Drupal::l($renderable_text, Url::fromUri('https://www.drupal.org'));
+ $this->assertEqual($l_renderable_text, $l);
+ });
// Test a themed link with plain text 'text'.
$type_link_plain_array = array(
@@ -171,7 +182,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 +191,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/Render/RenderCacheTest.php b/core/modules/system/src/Tests/Render/RenderCacheTest.php
index b4317d1..975358c 100644
--- a/core/modules/system/src/Tests/Render/RenderCacheTest.php
+++ b/core/modules/system/src/Tests/Render/RenderCacheTest.php
@@ -77,14 +77,14 @@ protected function doTestUser1WithContexts($contexts) {
];
$element = $test_element;
$element['#markup'] = 'content for user 1';
- $output = \Drupal::service('renderer')->render($element);
+ $output = \Drupal::service('renderer')->renderRoot($element);
$this->assertEqual($output, 'content for user 1');
// Verify the cache is working by rendering the same element but with
// different markup passed in; the result should be the same.
$element = $test_element;
$element['#markup'] = 'should not be used';
- $output = \Drupal::service('renderer')->render($element);
+ $output = \Drupal::service('renderer')->renderRoot($element);
$this->assertEqual($output, 'content for user 1');
\Drupal::service('account_switcher')->switchBack();
@@ -93,7 +93,7 @@ protected function doTestUser1WithContexts($contexts) {
\Drupal::service('account_switcher')->switchTo($first_authenticated_user);
$element = $test_element;
$element['#markup'] = 'content for authenticated users';
- $output = \Drupal::service('renderer')->render($element);
+ $output = \Drupal::service('renderer')->renderRoot($element);
$this->assertEqual($output, 'content for authenticated users');
\Drupal::service('account_switcher')->switchBack();
@@ -102,7 +102,7 @@ protected function doTestUser1WithContexts($contexts) {
\Drupal::service('account_switcher')->switchTo($second_authenticated_user);
$element = $test_element;
$element['#markup'] = 'should not be used';
- $output = \Drupal::service('renderer')->render($element);
+ $output = \Drupal::service('renderer')->renderRoot($element);
$this->assertEqual($output, 'content for authenticated users');
\Drupal::service('account_switcher')->switchBack();
@@ -111,7 +111,7 @@ protected function doTestUser1WithContexts($contexts) {
\Drupal::service('account_switcher')->switchTo($admin_user);
$element = $test_element;
$element['#markup'] = 'content for admin user';
- $output = \Drupal::service('renderer')->render($element);
+ $output = \Drupal::service('renderer')->renderRoot($element);
$this->assertEqual($output, 'content for admin user');
\Drupal::service('account_switcher')->switchBack();
}
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/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php
index 0289049..f02968b 100644
--- a/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php
+++ b/core/modules/taxonomy/src/Tests/Views/TaxonomyFieldTidTest.php
@@ -7,6 +7,7 @@
namespace Drupal\taxonomy\Tests\Views;
+use Drupal\Core\Render\RenderContext;
use Drupal\views\Views;
/**
@@ -24,10 +25,15 @@ class TaxonomyFieldTidTest extends TaxonomyTestBase {
public static $testViews = array('test_taxonomy_tid_field');
function testViewsHandlerTidField() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$view = Views::getView('test_taxonomy_tid_field');
$this->executeView($view);
- $actual = $view->field['name']->advancedRender($view->result[0]);
+ $actual = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$expected = \Drupal::l($this->term1->label(), $this->term1->urlInfo());
$this->assertEqual($expected, $actual);
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 = '
';
- return array('#markup' => $output);
+ '#suffix' => '',
+ ];
}
}
diff --git a/core/modules/user/src/Tests/UserBlocksTest.php b/core/modules/user/src/Tests/UserBlocksTest.php
index 366f519..830b87a 100644
--- a/core/modules/user/src/Tests/UserBlocksTest.php
+++ b/core/modules/user/src/Tests/UserBlocksTest.php
@@ -105,7 +105,7 @@ function testWhosOnlineBlock() {
// Test block output.
\Drupal::currentUser()->setAccount($user1);
$content = entity_view($block, 'block');
- $this->setRawContent(render($content));
+ $this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertRaw(t('2 users'), 'Correct number of online users (2 users).');
$this->assertText($user1->getUsername(), 'Active user 1 found in online list.');
$this->assertText($user2->getUsername(), 'Active user 2 found in online list.');
diff --git a/core/modules/user/src/Tests/UserFieldsTest.php b/core/modules/user/src/Tests/UserFieldsTest.php
index 50564d0..dc3bef2 100644
--- a/core/modules/user/src/Tests/UserFieldsTest.php
+++ b/core/modules/user/src/Tests/UserFieldsTest.php
@@ -48,7 +48,7 @@ function testUserFields() {
'mail' => 'foobar@example.com',
]);
$build = user_view($user);
- $output = \Drupal::service('renderer')->render($build);
+ $output = \Drupal::service('renderer')->renderRoot($build);
$this->setRawContent($output);
$userEmail = $user->getEmail();
$this->assertText($userEmail, "User's mail field is found in the twig template");
diff --git a/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php b/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php
index c2c0c93..5db1e3e 100644
--- a/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php
+++ b/core/modules/user/src/Tests/Views/HandlerFieldUserNameTest.php
@@ -7,6 +7,7 @@
namespace Drupal\user\Tests\Views;
+use Drupal\Core\Render\RenderContext;
use Drupal\views\Views;
/**
@@ -25,6 +26,9 @@ class HandlerFieldUserNameTest extends UserTestBase {
public static $testViews = array('test_views_handler_field_user_name');
public function testUserName() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$this->drupalLogin($this->drupalCreateUser(array('access user profiles')));
// Set defaults.
@@ -37,13 +41,17 @@ public function testUserName() {
$this->executeView($view);
$anon_name = $this->config('user.settings')->get('anonymous');
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertTrue(strpos($render, $anon_name) !== FALSE, 'For user 0 it should use the default anonymous name by default.');
$username = $this->randomMachineName();
$view->result[0]->_entity->setUsername($username);
$view->result[0]->_entity->uid->value = 1;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.');
$this->assertTrue(strpos($render, 'user/1') !== FALSE, 'If link to user is checked the link to the user should appear as well.');
@@ -52,7 +60,9 @@ public function testUserName() {
$username = $this->randomMachineName();
$view->result[0]->_entity->setUsername($username);
$view->result[0]->_entity->uid->value = 1;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $username, 'If the user is not linked the username should be printed out for a normal user.');
}
@@ -61,13 +71,18 @@ public function testUserName() {
* Tests that the field handler works when no additional fields are added.
*/
public function testNoAdditionalFields() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$view = Views::getView('test_views_handler_field_user_name');
$this->executeView($view);
$username = $this->randomMachineName();
$view->result[0]->_entity->setUsername($username);
$view->result[0]->_entity->uid->value = 1;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.');
}
diff --git a/core/modules/views/src/Controller/ViewAjaxController.php b/core/modules/views/src/Controller/ViewAjaxController.php
index 6b7e1d5..83a203b 100644
--- a/core/modules/views/src/Controller/ViewAjaxController.php
+++ b/core/modules/views/src/Controller/ViewAjaxController.php
@@ -175,8 +175,7 @@ public function ajaxView(Request $request) {
$view->dom_id = $dom_id;
if ($preview = $view->preview($display_id, $args)) {
- $response->addCommand(new ReplaceCommand(".js-view-dom-id-$dom_id", $this->renderer->render($preview)));
- $response->setAttachments($preview['#attached']);
+ $response->addCommand(new ReplaceCommand(".js-view-dom-id-$dom_id", $preview));
}
return $response;
}
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..4bc9af7 100644
--- a/core/modules/views/src/Tests/Handler/AreaEntityTest.php
+++ b/core/modules/views/src/Tests/Handler/AreaEntityTest.php
@@ -122,9 +122,11 @@ 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));
+ $this->setRawContent(\Drupal::service('renderer')->renderRoot($preview));
$view_class = 'js-view-dom-id-' . $view->dom_id;
$header_xpath = '//div[@class = "' . $view_class . '"]/div[1]';
$footer_xpath = '//div[@class = "' . $view_class . '"]/div[3]';
@@ -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..bdc1e48 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');
@@ -127,7 +127,7 @@ public function testAreaAccess() {
$this->assertEqual(0, count($handlers));
$output = $view->preview();
- $output = \Drupal::service('renderer')->render($output);
+ $output = \Drupal::service('renderer')->renderRoot($output);
// The area output should not be present since access was denied.
$this->assertFalse(strpos($output, 'a custom string') !== FALSE);
$view->destroy();
@@ -149,7 +149,7 @@ public function testAreaAccess() {
$handlers = $view->display_handler->getHandlers('empty');
$output = $view->preview();
- $output = \Drupal::service('renderer')->render($output);
+ $output = \Drupal::service('renderer')->renderRoot($output);
$this->assertTrue(strpos($output, 'a custom string') !== FALSE);
$this->assertEqual(1, count($handlers));
}
@@ -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/FieldGroupRowsTest.php b/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php
index 2aa0e9c..96976db 100644
--- a/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php
+++ b/core/modules/views/src/Tests/Handler/FieldGroupRowsTest.php
@@ -8,6 +8,7 @@
namespace Drupal\views\Tests\Handler;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\Render\RenderContext;
use Drupal\views\Views;
/**
@@ -67,6 +68,9 @@ protected function setUp() {
* Testing the "Grouped rows" functionality.
*/
public function testGroupRows() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$edit = array(
'title' => $this->randomMachineName(),
$this->fieldName => array('a', 'b', 'c'),
@@ -77,7 +81,10 @@ public function testGroupRows() {
// Test grouped rows.
$this->executeView($view);
- $this->assertEqual($view->field[$this->fieldName]->advancedRender($view->result[0]), 'a, b, c');
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field[$this->fieldName]->advancedRender($view->result[0]);
+ });
+ $this->assertEqual($output, 'a, b, c');
// Change the group_rows checkbox to false.
$view = Views::getView('test_group_rows');
@@ -88,11 +95,20 @@ public function testGroupRows() {
$view->render();
$view->row_index = 0;
- $this->assertEqual($view->field[$this->fieldName]->advancedRender($view->result[0]), 'a');
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field[$this->fieldName]->advancedRender($view->result[0]);
+ });
+ $this->assertEqual($output, 'a');
$view->row_index = 1;
- $this->assertEqual($view->field[$this->fieldName]->advancedRender($view->result[1]), 'b');
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field[$this->fieldName]->advancedRender($view->result[1]);
+ });
+ $this->assertEqual($output, 'b');
$view->row_index = 2;
- $this->assertEqual($view->field[$this->fieldName]->advancedRender($view->result[2]), 'c');
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field[$this->fieldName]->advancedRender($view->result[2]);
+ });
+ $this->assertEqual($output, 'c');
}
}
diff --git a/core/modules/views/src/Tests/Handler/FieldUnitTest.php b/core/modules/views/src/Tests/Handler/FieldUnitTest.php
index 7c319d4..5a5d73f 100644
--- a/core/modules/views/src/Tests/Handler/FieldUnitTest.php
+++ b/core/modules/views/src/Tests/Handler/FieldUnitTest.php
@@ -7,6 +7,7 @@
namespace Drupal\views\Tests\Handler;
+use Drupal\Core\Render\RenderContext;
use Drupal\views\Tests\ViewUnitTestBase;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\Views;
@@ -52,12 +53,18 @@ protected function viewsData() {
* Tests that the render function is called.
*/
public function testRender() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$view = Views::getView('test_field_tokens');
$this->executeView($view);
$random_text = $this->randomMachineName();
$view->field['job']->setTestValue($random_text);
- $this->assertEqual($view->field['job']->theme($view->result[0]), $random_text, 'Make sure the render method rendered the manual set value.');
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['job']->theme($view->result[0]);
+ });
+ $this->assertEqual($output, $random_text, 'Make sure the render method rendered the manual set value.');
}
/**
@@ -141,6 +148,9 @@ protected function assertNotSubString($haystack, $needle, $message = '', $group
* Tests general rewriting of the output.
*/
public function testRewrite() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$view = Views::getView('test_view');
$view->initHandlers();
$this->executeView($view);
@@ -149,11 +159,15 @@ public function testRewrite() {
// Don't check the rewrite checkbox, so the text shouldn't appear.
$id_field->options['alter']['text'] = $random_text = $this->randomMachineName();
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertNotSubString($output, $random_text);
$id_field->options['alter']['alter_text'] = TRUE;
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($output, $random_text);
}
@@ -161,6 +175,9 @@ public function testRewrite() {
* Tests the field tokens, row level and field level.
*/
public function testFieldTokens() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$view = Views::getView('test_field_tokens');
$this->executeView($view);
$name_field_0 = $view->field['name'];
@@ -182,19 +199,25 @@ public function testFieldTokens() {
$expected_output_1 = "$row->views_test_data_name $row->views_test_data_name";
$expected_output_2 = "$row->views_test_data_name $row->views_test_data_name $row->views_test_data_name";
- $output = $name_field_0->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_0, $row) {
+ return $name_field_0->advancedRender($row);
+ });
$this->assertEqual($output, $expected_output_0, format_string('Test token replacement: "!token" gave "!output"', [
'!token' => $name_field_0->options['alter']['text'],
'!output' => $output,
]));
- $output = $name_field_1->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_1, $row) {
+ return $name_field_1->advancedRender($row);
+ });
$this->assertEqual($output, $expected_output_1, format_string('Test token replacement: "!token" gave "!output"', [
'!token' => $name_field_1->options['alter']['text'],
'!output' => $output,
]));
- $output = $name_field_2->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field_2, $row) {
+ return $name_field_2->advancedRender($row);
+ });
$this->assertEqual($output, $expected_output_2, format_string('Test token replacement: "!token" gave "!output"', [
'!token' => $name_field_2->options['alter']['text'],
'!output' => $output,
@@ -207,7 +230,9 @@ public function testFieldTokens() {
$random_text = $this->randomMachineName();
$job_field->setTestValue($random_text);
- $output = $job_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) {
+ return $job_field->advancedRender($row);
+ });
$this->assertSubString($output, $random_text, format_string('Make sure the self token (!token => !value) appears in the output (!output)', [
'!value' => $random_text,
'!output' => $output,
@@ -219,7 +244,9 @@ public function testFieldTokens() {
$job_field->options['alter']['text'] = $old_token;
$random_text = $this->randomMachineName();
$job_field->setTestValue($random_text);
- $output = $job_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($job_field, $row) {
+ return $job_field->advancedRender($row);
+ });
$this->assertSubString($output, $old_token, format_string('Make sure the old token style (!token => !value) is not changed in the output (!output)', [
'!value' => $random_text,
'!output' => $output,
@@ -231,13 +258,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 +275,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']);
}
@@ -266,6 +295,9 @@ function testEmpty() {
* This tests alters the result to get easier and less coupled results.
*/
function _testHideIfEmpty() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$view = Views::getView('test_view');
$view->initDisplay();
$this->executeView($view);
@@ -282,22 +314,30 @@ function _testHideIfEmpty() {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $random_name, 'By default, a string should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "", 'By default, "" should not be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, '0', 'By default, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "0", 'By default, "0" should not be treated as empty.');
// Test when results are not rewritten and non-zero empty values are hidden.
@@ -307,22 +347,30 @@ function _testHideIfEmpty() {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $random_name, 'If hide_empty is checked, a string should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "", 'If hide_empty is checked, "" should be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, '0', 'If hide_empty is checked, but not empty_zero, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "0", 'If hide_empty is checked, but not empty_zero, "0" should not be treated as empty.');
// Test when results are not rewritten and all empty values are hidden.
@@ -332,12 +380,16 @@ function _testHideIfEmpty() {
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "", 'If hide_empty and empty_zero are checked, 0 should be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "", 'If hide_empty and empty_zero are checked, "0" should be treated as empty.');
// Test when results are rewritten to a valid string and non-zero empty
@@ -350,22 +402,30 @@ function _testHideIfEmpty() {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_value;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $random_name, 'If the rewritten string is not empty, it should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $random_name, 'If the rewritten string is not empty, "" should not be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $random_name, 'If the rewritten string is not empty, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $random_name, 'If the rewritten string is not empty, "0" should not be treated as empty.');
// Test when results are rewritten to an empty string and non-zero empty results are hidden.
@@ -377,22 +437,30 @@ function _testHideIfEmpty() {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $random_name, 'If the rewritten string is empty, it should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "", 'If the rewritten string is empty, "" should be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, '0', 'If the rewritten string is empty, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "0", 'If the rewritten string is empty, "0" should not be treated as empty.');
// Test when results are rewritten to zero as a string and non-zero empty
@@ -405,22 +473,30 @@ function _testHideIfEmpty() {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "0", 'If the rewritten string is zero and empty_zero is not checked, the string rewritten as 0 should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "0", 'If the rewritten string is zero and empty_zero is not checked, "" rewritten as 0 should not be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "0", 'If the rewritten string is zero and empty_zero is not checked, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "0", 'If the rewritten string is zero and empty_zero is not checked, "0" should not be treated as empty.');
// Test when results are rewritten to a valid string and non-zero empty
@@ -433,22 +509,30 @@ function _testHideIfEmpty() {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $random_value, 'If the original and rewritten strings are valid, it should not be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "", 'If either the original or rewritten string is invalid, "" should be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $random_value, 'If the original and rewritten strings are valid, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $random_value, 'If the original and rewritten strings are valid, "0" should not be treated as empty.');
// Test when results are rewritten to zero as a string and all empty
@@ -461,22 +545,30 @@ function _testHideIfEmpty() {
// Test a valid string.
$view->result[0]->{$column_map_reversed['name']} = $random_name;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "", 'If the rewritten string is zero, it should be treated as empty.');
// Test an empty string.
$view->result[0]->{$column_map_reversed['name']} = "";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "", 'If the rewritten string is zero, "" should be treated as empty.');
// Test zero as an integer.
$view->result[0]->{$column_map_reversed['name']} = 0;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "", 'If the rewritten string is zero, 0 should not be treated as empty.');
// Test zero as a string.
$view->result[0]->{$column_map_reversed['name']} = "0";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "", 'If the rewritten string is zero, "0" should not be treated as empty.');
}
@@ -484,6 +576,9 @@ function _testHideIfEmpty() {
* Tests the usage of the empty text.
*/
function _testEmptyText() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$view = Views::getView('test_view');
$view->initDisplay();
$this->executeView($view);
@@ -493,27 +588,37 @@ function _testEmptyText() {
$empty_text = $view->field['name']->options['empty'] = $this->randomMachineName();
$view->result[0]->{$column_map_reversed['name']} = "";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $empty_text, 'If a field is empty, the empty text should be used for the output.');
$view->result[0]->{$column_map_reversed['name']} = "0";
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, "0", 'If a field is 0 and empty_zero is not checked, the empty text should not be used for the output.');
$view->result[0]->{$column_map_reversed['name']} = "0";
$view->field['name']->options['empty_zero'] = TRUE;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $empty_text, 'If a field is 0 and empty_zero is checked, the empty text should be used for the output.');
$view->result[0]->{$column_map_reversed['name']} = "";
$view->field['name']->options['alter']['alter_text'] = TRUE;
$alter_text = $view->field['name']->options['alter']['text'] = $this->randomMachineName();
$view->field['name']->options['hide_alter_empty'] = FALSE;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $alter_text, 'If a field is empty, some rewrite text exists, but hide_alter_empty is not checked, render the rewrite text.');
$view->field['name']->options['hide_alter_empty'] = TRUE;
- $render = $view->field['name']->advancedRender($view->result[0]);
+ $render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
+ return $view->field['name']->advancedRender($view->result[0]);
+ });
$this->assertIdentical($render, $empty_text, 'If a field is empty, some rewrite text exists, and hide_alter_empty is checked, use the empty text.');
}
diff --git a/core/modules/views/src/Tests/Handler/FieldWebTest.php b/core/modules/views/src/Tests/Handler/FieldWebTest.php
index 3fde585..39e1eb2 100644
--- a/core/modules/views/src/Tests/Handler/FieldWebTest.php
+++ b/core/modules/views/src/Tests/Handler/FieldWebTest.php
@@ -10,6 +10,7 @@
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\UrlHelper;
+use Drupal\Core\Render\RenderContext;
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
use Drupal\views\Views;
@@ -197,6 +198,9 @@ protected function xpathContent($content, $xpath, array $arguments = array()) {
* Tests rewriting the output to a link.
*/
public function testAlterUrl() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$view = Views::getView('test_view');
$view->setDisplay();
$view->initHandlers();
@@ -211,13 +215,17 @@ public function testAlterUrl() {
// Tests that the suffix/prefix appears on the output.
$id_field->options['alter']['prefix'] = $prefix = $this->randomMachineName();
$id_field->options['alter']['suffix'] = $suffix = $this->randomMachineName();
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($output, $prefix);
$this->assertSubString($output, $suffix);
unset($id_field->options['alter']['prefix']);
unset($id_field->options['alter']['suffix']);
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($output, $path, 'Make sure that the path is part of the output');
// Some generic test code adapted from the UrlTest class, which tests
@@ -228,44 +236,60 @@ public function testAlterUrl() {
$expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['absolute' => $absolute]);
$alter['absolute'] = $absolute;
- $result = $id_field->theme($row);
+ $result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($result, $expected_result);
$expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['fragment' => 'foo', 'absolute' => $absolute]);
$alter['path'] = 'node/123#foo';
- $result = $id_field->theme($row);
+ $result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($result, $expected_result);
$expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['query' => ['foo' => NULL], 'absolute' => $absolute]);
$alter['path'] = 'node/123?foo';
- $result = $id_field->theme($row);
+ $result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($result, $expected_result);
$expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['query' => ['foo' => 'bar', 'bar' => 'baz'], 'absolute' => $absolute]);
$alter['path'] = 'node/123?foo=bar&bar=baz';
- $result = $id_field->theme($row);
+ $result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString(Html::decodeEntities($result), Html::decodeEntities($expected_result));
// @todo The route-based URL generator strips out NULL attributes.
// $expected_result = \Drupal::url('entity.node.canonical', ['node' => '123'], ['query' => ['foo' => NULL], 'fragment' => 'bar', 'absolute' => $absolute]);
$expected_result = \Drupal::urlGenerator()->generateFromPath('node/123', array('query' => array('foo' => NULL), 'fragment' => 'bar', 'absolute' => $absolute));
$alter['path'] = 'node/123?foo#bar';
- $result = $id_field->theme($row);
+ $result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString(Html::decodeEntities($result), Html::decodeEntities($expected_result));
$expected_result = \Drupal::url('', [], ['absolute' => $absolute]);
$alter['path'] = '';
- $result = $id_field->theme($row);
+ $result = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($result, $expected_result);
}
// Tests the replace spaces with dashes feature.
$id_field->options['alter']['replace_spaces'] = TRUE;
$id_field->options['alter']['path'] = $path = $this->randomMachineName() . ' ' . $this->randomMachineName();
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($output, str_replace(' ', '-', $path));
$id_field->options['alter']['replace_spaces'] = FALSE;
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
// The url has a space in it, so to check we have to decode the url output.
$this->assertSubString(urldecode($output), $path);
@@ -273,44 +297,60 @@ public function testAlterUrl() {
// Switch on the external flag should output an external url as well.
$id_field->options['alter']['external'] = TRUE;
$id_field->options['alter']['path'] = $path = 'www.drupal.org';
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($output, 'http://www.drupal.org');
// Setup a not external url, which shouldn't lead to an external url.
$id_field->options['alter']['external'] = FALSE;
$id_field->options['alter']['path'] = $path = 'www.drupal.org';
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertNotSubString($output, 'http://www.drupal.org');
// Tests the transforming of the case setting.
$id_field->options['alter']['path'] = $path = $this->randomMachineName();
$id_field->options['alter']['path_case'] = 'none';
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($output, $path);
// Switch to uppercase and lowercase.
$id_field->options['alter']['path_case'] = 'upper';
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($output, strtoupper($path));
$id_field->options['alter']['path_case'] = 'lower';
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($output, strtolower($path));
// Switch to ucfirst and ucwords.
$id_field->options['alter']['path_case'] = 'ucfirst';
$id_field->options['alter']['path'] = 'drupal has a great community';
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($output, UrlHelper::encodePath('Drupal has a great community'));
$id_field->options['alter']['path_case'] = 'ucwords';
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$this->assertSubString($output, UrlHelper::encodePath('Drupal Has A Great Community'));
unset($id_field->options['alter']['path_case']);
// Tests the linkclass setting and see whether it actually exists in the
// output.
$id_field->options['alter']['link_class'] = $class = $this->randomMachineName();
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$elements = $this->xpathContent($output, '//a[contains(@class, :class)]', array(':class' => $class));
$this->assertTrue($elements);
// @fixme link_class, alt, rel cannot be unset, which should be fixed.
@@ -318,21 +358,27 @@ public function testAlterUrl() {
// Tests the alt setting.
$id_field->options['alter']['alt'] = $rel = $this->randomMachineName();
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$elements = $this->xpathContent($output, '//a[contains(@title, :alt)]', array(':alt' => $rel));
$this->assertTrue($elements);
$id_field->options['alter']['alt'] = '';
// Tests the rel setting.
$id_field->options['alter']['rel'] = $rel = $this->randomMachineName();
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$elements = $this->xpathContent($output, '//a[contains(@rel, :rel)]', array(':rel' => $rel));
$this->assertTrue($elements);
$id_field->options['alter']['rel'] = '';
// Tests the target setting.
$id_field->options['alter']['target'] = $target = $this->randomMachineName();
- $output = $id_field->theme($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($id_field, $row) {
+ return $id_field->theme($row);
+ });
$elements = $this->xpathContent($output, '//a[contains(@target, :target)]', array(':target' => $target));
$this->assertTrue($elements);
unset($id_field->options['alter']['target']);
@@ -342,6 +388,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 +400,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 +422,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 +442,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 +462,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}"));
}
@@ -451,6 +499,9 @@ public function testFieldClasses() {
* Tests trimming/read-more/ellipses.
*/
public function testTextRendering() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = \Drupal::service('renderer');
+
$view = Views::getView('test_field_output');
$view->initHandlers();
$name_field = $view->field['name'];
@@ -463,18 +514,24 @@ public function testTextRendering() {
$row = $view->result[0];
$name_field->options['alter']['strip_tags'] = TRUE;
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertSubString($output, $random_text, 'Find text without html if stripping of views field output is enabled.');
$this->assertNotSubString($output, $html_text, 'Find no text with the html if stripping of views field output is enabled.');
// Tests preserving of html tags.
$name_field->options['alter']['preserve_tags'] = '
';
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertSubString($output, $random_text, 'Find text without html if stripping of views field output is enabled but a div is allowed.');
$this->assertSubString($output, $html_text, 'Find text with the html if stripping of views field output is enabled but a div is allowed.');
$name_field->options['alter']['strip_tags'] = FALSE;
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertSubString($output, $random_text, 'Find text without html if stripping of views field output is disabled.');
$this->assertSubString($output, $html_text, 'Find text with the html if stripping of views field output is disabled.');
@@ -483,13 +540,17 @@ public function testTextRendering() {
$views_test_data_name = $row->views_test_data_name;
$row->views_test_data_name = ' ' . $views_test_data_name . ' ';
$name_field->options['alter']['trim_whitespace'] = TRUE;
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertSubString($output, $views_test_data_name, 'Make sure the trimmed text can be found if trimming is enabled.');
$this->assertNotSubString($output, $row->views_test_data_name, 'Make sure the untrimmed text can be found if trimming is enabled.');
$name_field->options['alter']['trim_whitespace'] = FALSE;
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertSubString($output, $views_test_data_name, 'Make sure the trimmed text can be found if trimming is disabled.');
$this->assertSubString($output, $row->views_test_data_name, 'Make sure the untrimmed text can be found if trimming is disabled.');
@@ -502,12 +563,16 @@ public function testTextRendering() {
$name_field->options['alter']['max_length'] = 5;
$trimmed_name = Unicode::substr($row->views_test_data_name, 0, 5);
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertSubString($output, $trimmed_name, format_string('Make sure the trimmed output (!trimmed) appears in the rendered output (!output).', array('!trimmed' => $trimmed_name, '!output' => $output)));
$this->assertNotSubString($output, $row->views_test_data_name, format_string("Make sure the untrimmed value (!untrimmed) shouldn't appear in the rendered output (!output).", array('!untrimmed' => $row->views_test_data_name, '!output' => $output)));
$name_field->options['alter']['max_length'] = 9;
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertSubString($output, $trimmed_name, format_string('Make sure the untrimmed (!untrimmed) output appears in the rendered output (!output).', array('!trimmed' => $trimmed_name, '!output' => $output)));
// Take word_boundary into account for the tests.
@@ -547,7 +612,9 @@ public function testTextRendering() {
foreach ($tuples as $tuple) {
$row->views_test_data_name = $tuple['value'];
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
if ($tuple['trimmed']) {
$this->assertNotSubString($output, $tuple['value'], format_string('The untrimmed value (!untrimmed) should not appear in the trimmed output (!output).', array('!untrimmed' => $tuple['value'], '!output' => $output)));
@@ -564,22 +631,30 @@ public function testTextRendering() {
$name_field->options['alter']['more_link_text'] = $more_text = $this->randomMachineName();
$name_field->options['alter']['more_link_path'] = $more_path = $this->randomMachineName();
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertSubString($output, $more_text, 'Make sure a read more text is displayed if the output got trimmed');
$this->assertTrue($this->xpathContent($output, '//a[contains(@href, :path)]', array(':path' => $more_path)), 'Make sure the read more link points to the right destination.');
$name_field->options['alter']['more_link'] = FALSE;
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertNotSubString($output, $more_text, 'Make sure no read more text appears.');
$this->assertFalse($this->xpathContent($output, '//a[contains(@href, :path)]', array(':path' => $more_path)), 'Make sure no read more link appears.');
// Check for the ellipses.
$row->views_test_data_name = $this->randomMachineName(8);
$name_field->options['alter']['max_length'] = 5;
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertSubString($output, '…', 'An ellipsis should appear if the output is trimmed');
$name_field->options['alter']['max_length'] = 10;
- $output = $name_field->advancedRender($row);
+ $output = $renderer->executeInRenderContext(new RenderContext(), function () use ($name_field, $row) {
+ return $name_field->advancedRender($row);
+ });
$this->assertNotSubString($output, '…', 'No ellipsis should appear if the output is not trimmed');
}
diff --git a/core/modules/views/src/Tests/Plugin/CacheTest.php b/core/modules/views/src/Tests/Plugin/CacheTest.php
index bae30f5..08e1565 100644
--- a/core/modules/views/src/Tests/Plugin/CacheTest.php
+++ b/core/modules/views/src/Tests/Plugin/CacheTest.php
@@ -7,6 +7,7 @@
namespace Drupal\views\Tests\Plugin;
+use Drupal\Core\Render\RenderContext;
use Drupal\node\Entity\Node;
use Drupal\views\Tests\ViewUnitTestBase;
use Drupal\views\Views;
@@ -282,14 +283,18 @@ function testHeaderStorage() {
$output = $view->buildRenderable();
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
- $renderer->render($output);
+ $renderer->executeInRenderContext(new RenderContext(), function () use (&$output, $renderer) {
+ return $renderer->render($output);;
+ });
unset($view->pre_render_called);
$view->destroy();
$view->setDisplay();
$output = $view->buildRenderable();
- $renderer->render($output);
+ $renderer->executeInRenderContext(new RenderContext(), function () use (&$output, $renderer) {
+ return $renderer->render($output);;
+ });
$this->assertTrue(in_array('views_test_data/test', $output['#attached']['library']), 'Make sure libraries are added for cached views.');
$this->assertEqual(['foo' => 'bar'], $output['#attached']['drupalSettings'], 'Make sure drupalSettings are added for cached views.');
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('/
/', $output), 0, 'The pager is not rendered.');
}
diff --git a/core/modules/views/src/Tests/Plugin/StyleGridTest.php b/core/modules/views/src/Tests/Plugin/StyleGridTest.php
index 1f4e9b4..d5d7e60 100644
--- a/core/modules/views/src/Tests/Plugin/StyleGridTest.php
+++ b/core/modules/views/src/Tests/Plugin/StyleGridTest.php
@@ -72,7 +72,7 @@ protected function assertGrid(ViewExecutable $view, $alignment, $columns) {
$view->style_plugin->options['columns'] = $columns;
$this->executeView($view);
$output = $view->preview();
- $output = drupal_render($output);
+ $output = \Drupal::service('renderer')->renderRoot($output);
$this->setRawContent($output);
if (!in_array($alignment, $this->alignmentsTested)) {
$result = $this->xpath('//div[contains(@class, "views-view-grid") and contains(@class, :alignment) and contains(@class, :columns)]', array(':alignment' => $alignment, ':columns' => 'cols-' . $columns));
diff --git a/core/modules/views/src/Tests/Plugin/StyleHtmlListTest.php b/core/modules/views/src/Tests/Plugin/StyleHtmlListTest.php
index 0642eff..80243d1 100644
--- a/core/modules/views/src/Tests/Plugin/StyleHtmlListTest.php
+++ b/core/modules/views/src/Tests/Plugin/StyleHtmlListTest.php
@@ -31,7 +31,7 @@ class StyleHtmlListTest extends ViewUnitTestBase {
function testDefaultRowClasses() {
$view = Views::getView('test_style_html_list');
$output = $view->preview();
- $output = drupal_render($output);
+ $output = \Drupal::service('renderer')->renderRoot($output);
// Check that an empty class attribute is not added if the wrapper class is
// not set.
@@ -46,7 +46,7 @@ function testDefaultRowClasses() {
$view->style_plugin->options['wrapper_class'] = 'wrapper-class';
$output = $view->preview();
- $output = drupal_render($output);
+ $output = \Drupal::service('renderer')->renderRoot($output);
// Check that class attribute is present if the wrapper class is set.
$this->assertTrue(strpos($output, '
') !== FALSE, 'Class is added to DIV');
diff --git a/core/modules/views/src/Tests/Plugin/StyleMappingTest.php b/core/modules/views/src/Tests/Plugin/StyleMappingTest.php
index 24b06d2..2712958 100644
--- a/core/modules/views/src/Tests/Plugin/StyleMappingTest.php
+++ b/core/modules/views/src/Tests/Plugin/StyleMappingTest.php
@@ -51,7 +51,7 @@ public function testMappedOutput() {
*/
protected function mappedOutputHelper($view) {
$output = $view->preview();
- $rendered_output = drupal_render($output);
+ $rendered_output = \Drupal::service('renderer')->renderRoot($output);
$this->storeViewPreview($rendered_output);
$rows = $this->elements->body->div->div->div;
$data_set = $this->dataSet();
diff --git a/core/modules/views/src/Tests/Plugin/StyleTableUnitTest.php b/core/modules/views/src/Tests/Plugin/StyleTableUnitTest.php
index 3d132df..28eff6b 100644
--- a/core/modules/views/src/Tests/Plugin/StyleTableUnitTest.php
+++ b/core/modules/views/src/Tests/Plugin/StyleTableUnitTest.php
@@ -123,7 +123,7 @@ public function testTable() {
$this->prepareView($view);
$view->field['name']->options['exclude'] = TRUE;
$output = $view->preview();
- $output = drupal_render($output);
+ $output = \Drupal::service('renderer')->renderRoot($output);
$this->assertFalse(strpos($output, 'views-field-name') !== FALSE, "Excluded field's wrapper was not rendered.");
$view->destroy();
@@ -131,7 +131,7 @@ public function testTable() {
// rendered.
$this->executeView($view);
$output = $view->preview();
- $output = drupal_render($output);
+ $output = \Drupal::service('renderer')->renderRoot($output);
$this->assertFalse(strpos($output, 'custom text') !== FALSE, 'Empty handler was not rendered on a non empty table.');
@@ -140,7 +140,7 @@ public function testTable() {
$view->executed = TRUE;
$view->result = array();
$output = $view->preview();
- $output = drupal_render($output);
+ $output = \Drupal::service('renderer')->renderRoot($output);
$this->assertTrue(strpos($output, 'custom text') !== FALSE, 'Empty handler got rendered on an empty table.');
}
diff --git a/core/modules/views/src/Tests/Plugin/StyleTest.php b/core/modules/views/src/Tests/Plugin/StyleTest.php
index 86c2f91..a0675c2 100644
--- a/core/modules/views/src/Tests/Plugin/StyleTest.php
+++ b/core/modules/views/src/Tests/Plugin/StyleTest.php
@@ -46,6 +46,9 @@ protected function setUp() {
* Tests the general rendering of styles.
*/
public function testStyle() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
+
// This run use the test row plugin and render with it.
$view = Views::getView('test_view');
$view->setDisplay();
@@ -65,7 +68,7 @@ public function testStyle() {
$view->rowPlugin->setOutput($random_text);
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, $random_text) !== FALSE, 'Make sure that the rendering of the row plugin appears in the output of the view.');
// Test without row plugin support.
@@ -85,7 +88,7 @@ public function testStyle() {
// rendered.
$view->style_plugin->setOutput($random_text);
$output = $view->preview();
- $output = drupal_render($output);
+ $output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, $random_text) !== FALSE, 'Make sure that the rendering of the style plugin appears in the output of the view.');
}
@@ -229,7 +232,7 @@ function testCustomRowClasses() {
$view->style_plugin->options['row_class'] = $random_name . " test-token-{{ name }}";
$output = $view->preview();
- $this->storeViewPreview(drupal_render($output));
+ $this->storeViewPreview(\Drupal::service('renderer')->renderRoot($output));
$rows = $this->elements->body->div->div->div;
$count = 0;
diff --git a/core/modules/views/src/Tests/Plugin/StyleUnformattedTest.php b/core/modules/views/src/Tests/Plugin/StyleUnformattedTest.php
index 0835d98..083a975 100644
--- a/core/modules/views/src/Tests/Plugin/StyleUnformattedTest.php
+++ b/core/modules/views/src/Tests/Plugin/StyleUnformattedTest.php
@@ -30,7 +30,7 @@ function testDefaultRowClasses() {
$view = Views::getView('test_view');
$view->setDisplay();
$output = $view->preview();
- $this->storeViewPreview(drupal_render($output));
+ $this->storeViewPreview(\Drupal::service('renderer')->renderRoot($output));
$rows = $this->elements->body->div->div->div;
$count = 0;
diff --git a/core/modules/views/src/Tests/ViewElementTest.php b/core/modules/views/src/Tests/ViewElementTest.php
index bd17747..014f2ea 100644
--- a/core/modules/views/src/Tests/ViewElementTest.php
+++ b/core/modules/views/src/Tests/ViewElementTest.php
@@ -52,12 +52,14 @@ protected function setUp() {
* Tests the rendered output and form output of a view element.
*/
public function testViewElement() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$view = Views::getView('test_view_embed');
$view->setDisplay();
// Set the content as our rendered array.
$render = $this->render;
- $this->setRawContent(drupal_render($render));
+ $this->setRawContent($renderer->renderRoot($render));
$xpath = $this->xpath('//div[@class="views-element-container"]');
$this->assertTrue($xpath, 'The view container has been found in the rendered output.');
@@ -102,7 +104,7 @@ public function testViewElement() {
// Test the render array again.
$render = $this->render;
- $this->setRawContent(drupal_render($render));
+ $this->setRawContent($renderer->renderRoot($render));
// There should be 1 row in the results, 'John' arg 25.
$xpath = $this->xpath('//div[@class="view-content"]/div');
$this->assertEqual(count($xpath), 1);
@@ -118,13 +120,15 @@ public function testViewElement() {
* embed display plugin.
*/
public function testViewElementEmbed() {
+ /** @var \Drupal\Core\Render\RendererInterface $renderer */
+ $renderer = $this->container->get('renderer');
$view = Views::getView('test_view_embed');
$view->setDisplay('embed_1');
// Set the content as our rendered array.
$render = $this->render;
$render['#embed'] = TRUE;
- $this->setRawContent(drupal_render($render));
+ $this->setRawContent($renderer->renderRoot($render));
$xpath = $this->xpath('//div[@class="views-element-container"]');
$this->assertTrue($xpath, 'The view container has been found in the rendered output.');
@@ -170,7 +174,7 @@ public function testViewElementEmbed() {
// Test the render array again.
$render = $this->render;
$render['#embed'] = TRUE;
- $this->setRawContent(drupal_render($render));
+ $this->setRawContent($renderer->renderRoot($render));
// There should be 1 row in the results, 'John' arg 25.
$xpath = $this->xpath('//div[@class="view-content"]/div');
$this->assertEqual(count($xpath), 1);
diff --git a/core/modules/views/src/Tests/ViewRenderTest.php b/core/modules/views/src/Tests/ViewRenderTest.php
index ac60e6a..bbf3fe1 100644
--- a/core/modules/views/src/Tests/ViewRenderTest.php
+++ b/core/modules/views/src/Tests/ViewRenderTest.php
@@ -40,7 +40,7 @@ public function testRender() {
// Make sure that the rendering just calls the preprocess function once.
$view = Views::getView('test_view_render');
$output = $view->preview();
- drupal_render($output);
+ $this->container->get('renderer')->renderRoot($output);
$this->assertEqual(\Drupal::state()->get('views_render.test'), 1);
}
diff --git a/core/modules/views/src/Tests/ViewsTemplateTest.php b/core/modules/views/src/Tests/ViewsTemplateTest.php
index 966029c..c67befe 100644
--- a/core/modules/views/src/Tests/ViewsTemplateTest.php
+++ b/core/modules/views/src/Tests/ViewsTemplateTest.php
@@ -45,7 +45,7 @@ public function testTemplate() {
$output = $view->preview();
// Check if we got the rendered output of our template file.
- $this->assertTrue(strpos(drupal_render($output), 'This module defines its own display template.') !== FALSE, 'Display plugin DisplayTemplateTest defines its own template.');
+ $this->assertTrue(strpos(\Drupal::service('renderer')->renderRoot($output), 'This module defines its own display template.') !== FALSE, 'Display plugin DisplayTemplateTest defines its own template.');
}
diff --git a/core/modules/views_ui/src/Controller/ViewsUIController.php b/core/modules/views_ui/src/Controller/ViewsUIController.php
index f03328a..474f7bc 100644
--- a/core/modules/views_ui/src/Controller/ViewsUIController.php
+++ b/core/modules/views_ui/src/Controller/ViewsUIController.php
@@ -157,7 +157,7 @@ public function ajaxOperation(ViewEntityInterface $view, $op, Request $request)
if ($request->request->get('js')) {
$list = $this->entityManager()->getListBuilder('view')->render();
$response = new AjaxResponse();
- $response->addCommand(new ReplaceCommand('#views-entity-list', drupal_render($list)));
+ $response->addCommand(new ReplaceCommand('#views-entity-list', $list));
return $response;
}
diff --git a/core/modules/views_ui/src/Tests/CustomBooleanTest.php b/core/modules/views_ui/src/Tests/CustomBooleanTest.php
index f9a990b..08fbda8 100644
--- a/core/modules/views_ui/src/Tests/CustomBooleanTest.php
+++ b/core/modules/views_ui/src/Tests/CustomBooleanTest.php
@@ -100,7 +100,7 @@ public function testCustomOption() {
$view = Views::getView('test_view');
$output = $view->preview();
- $output = drupal_render($output);
+ $output = \Drupal::service('renderer')->renderRoot($output);
$replacements = array('%type' => $type);
$this->{$values['test']}(strpos($output, $values['true']), format_string('Expected custom boolean TRUE value in output for %type.', $replacements));
diff --git a/core/modules/views_ui/src/ViewEditForm.php b/core/modules/views_ui/src/ViewEditForm.php
index fe33da1..6cfaf5d 100644
--- a/core/modules/views_ui/src/ViewEditForm.php
+++ b/core/modules/views_ui/src/ViewEditForm.php
@@ -685,12 +685,12 @@ public function rebuildCurrentTab(ViewUI $view, AjaxResponse $response, $display
// Regenerate the main display area.
$build = $this->getDisplayTab($view);
static::addMicroweights($build);
- $response->addCommand(new HtmlCommand('#views-tab-' . $display_id, drupal_render($build)));
+ $response->addCommand(new HtmlCommand('#views-tab-' . $display_id, $build));
// Regenerate the top area so changes to display names and order will appear.
$build = $this->renderDisplayTop($view);
static::addMicroweights($build);
- $response->addCommand(new ReplaceCommand('#views-display-top', drupal_render($build)));
+ $response->addCommand(new ReplaceCommand('#views-display-top', $build));
}
/**
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
index e0c7ff4..2037588 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
@@ -66,14 +66,14 @@ public function testBubblingWithoutPreRender() {
];
// Render the element and verify the presence of #attached JavaScript.
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$expected_libraries = ['test/parent', 'test/child', 'test/subchild'];
$this->assertEquals($element['#attached']['library'], $expected_libraries, 'The element, child and subchild #attached libraries are included.');
// Load the element from cache and verify the presence of the #attached
// JavaScript.
$element = ['#cache' => ['keys' => ['simpletest', 'drupal_render', 'children_attached']]];
- $this->assertTrue(strlen($this->renderer->render($element)) > 0, 'The element was retrieved from cache.');
+ $this->assertTrue(strlen($this->renderer->renderRoot($element)) > 0, 'The element was retrieved from cache.');
$this->assertEquals($element['#attached']['library'], $expected_libraries, 'The element, child and subchild #attached libraries are included.');
}
@@ -116,7 +116,7 @@ public function testContextBubblingCustomCacheBin() {
],
],
];
- $this->renderer->render($build);
+ $this->renderer->renderRoot($build);
$this->assertRenderCacheItem('parent:foo', [
'#cache_redirect' => TRUE,
@@ -143,7 +143,7 @@ public function testContextBubblingEdgeCases(array $element, array $expected_top
->method('convertTokensToKeys')
->willReturnArgument(0);
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$this->assertEquals($expected_top_level_contexts, $element['#cache']['contexts'], 'Expected cache contexts found.');
foreach ($expected_cache_items as $cid => $expected_cache_item) {
@@ -345,7 +345,7 @@ public function testConditionalCacheContextBubblingSelfHealing() {
// contexts: user.roles.
$element = $test_element;
$current_user_role = 'A';
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$this->assertRenderCacheItem('parent', [
'#cache_redirect' => TRUE,
'#cache' => [
@@ -369,7 +369,7 @@ public function testConditionalCacheContextBubblingSelfHealing() {
// contexts: foo, user.roles.
$element = $test_element;
$current_user_role = 'B';
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$this->assertRenderCacheItem('parent', [
'#cache_redirect' => TRUE,
'#cache' => [
@@ -401,7 +401,7 @@ public function testConditionalCacheContextBubblingSelfHealing() {
// and 'user.roles' cache contexts, resulting in a cache miss every time.)
$element = $test_element;
$current_user_role = 'A';
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$this->assertRenderCacheItem('parent', [
'#cache_redirect' => TRUE,
'#cache' => [
@@ -425,7 +425,7 @@ public function testConditionalCacheContextBubblingSelfHealing() {
// accessible => bubbled cache contexts: foo, bar, user.roles.
$element = $test_element;
$current_user_role = 'C';
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$final_parent_cache_item = [
'#cache_redirect' => TRUE,
'#cache' => [
@@ -449,7 +449,7 @@ public function testConditionalCacheContextBubblingSelfHealing() {
// Request 5: role A again, verifying the merging like we did for request 3.
$element = $test_element;
$current_user_role = 'A';
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$this->assertRenderCacheItem('parent', $final_parent_cache_item);
$this->assertRenderCacheItem('parent:bar:foo:r.A', [
'#attached' => [],
@@ -464,7 +464,7 @@ public function testConditionalCacheContextBubblingSelfHealing() {
// Request 6: role B again, verifying the merging like we did for request 3.
$element = $test_element;
$current_user_role = 'B';
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$this->assertRenderCacheItem('parent', $final_parent_cache_item);
$this->assertRenderCacheItem('parent:bar:foo:r.B', [
'#attached' => [],
@@ -570,7 +570,7 @@ public function testOverWriteCacheKeys() {
],
'#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingCacheOverwritePrerender'],
];
- $this->renderer->render($data);
+ $this->renderer->renderRoot($data);
}
}
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererTest.php b/core/tests/Drupal/Tests/Core/Render/RendererTest.php
index a2f91ea..3e3e3bd 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererTest.php
@@ -43,7 +43,7 @@ public function testRenderBasic($build, $expected, callable $setup_code = NULL)
$setup_code();
}
- $this->assertSame($expected, $this->renderer->render($build));
+ $this->assertSame($expected, $this->renderer->renderRoot($build));
}
/**
@@ -322,7 +322,7 @@ public function testRenderSorting() {
'#markup' => $first,
],
];
- $output = $this->renderer->render($elements);
+ $output = $this->renderer->renderRoot($elements);
// The lowest weight element should appear last in $output.
$this->assertTrue(strpos($output, $second) > strpos($output, $first), 'Elements were sorted correctly by weight.');
@@ -357,7 +357,7 @@ public function testRenderSortingWithSetHashSorted() {
),
'#sorted' => TRUE,
);
- $output = $this->renderer->render($elements);
+ $output = $this->renderer->renderRoot($elements);
// The elements should appear in output in the same order as the array.
$this->assertTrue(strpos($output, $second) < strpos($output, $first), 'Elements were not sorted.');
@@ -439,11 +439,11 @@ public function testRenderTwice() {
'#markup' => 'test',
];
- $this->assertEquals('test', $this->renderer->render($build));
+ $this->assertEquals('test', $this->renderer->renderRoot($build));
$this->assertTrue($build['#printed']);
// We don't want to reprint already printed render arrays.
- $this->assertEquals('', $this->renderer->render($build));
+ $this->assertEquals('', $this->renderer->renderRoot($build));
}
/**
@@ -470,10 +470,10 @@ protected function assertAccess($build, $access) {
$sensitive_content = $this->randomContextValue();
$build['#markup'] = $sensitive_content;
if ($access) {
- $this->assertSame($sensitive_content, $this->renderer->render($build));
+ $this->assertSame($sensitive_content, $this->renderer->renderRoot($build));
}
else {
- $this->assertSame('', $this->renderer->render($build));
+ $this->assertSame('', $this->renderer->renderRoot($build));
}
}
@@ -565,13 +565,13 @@ public function testRenderCache() {
// Render the element and confirm that it goes through the rendering
// process (which will set $element['#printed']).
$element = $test_element;
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$this->assertTrue(isset($element['#printed']), 'No cache hit');
// Render the element again and confirm that it is retrieved from the cache
// instead (so $element['#printed'] will not be set).
$element = $test_element;
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$this->assertFalse(isset($element['#printed']), 'Cache hit');
// Test that cache tags are correctly collected from the render element,
@@ -608,7 +608,7 @@ public function testRenderCacheMaxAge($max_age, $is_render_cached, $render_cache
],
'#markup' => '',
];
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$cache_item = $this->cacheFactory->get('render')->get('render_cache_test:en:stark');
if (!$is_render_cached) {
@@ -657,7 +657,7 @@ public function testRenderCacheProperties(array $expected_results) {
'child2' => ['#markup' => 2],
'#custom_property' => ['custom_value'],
];
- $this->renderer->render($element);
+ $this->renderer->renderRoot($element);
$cache = $this->cacheFactory->get('render');
$data = $cache->get('render_cache_test:en:stark')->data;