Commit 68d4f0be authored by alexpott's avatar alexpott

Issue #2511472 by Wim Leers, Fabianx, dawehner: Refactor all usages of...

Issue #2511472 by Wim Leers, Fabianx, dawehner: Refactor all usages of drupal_render()/Renderer::render() that break #2450993
parent 88163fde
......@@ -821,7 +821,7 @@ services:
- { name: event_subscriber }
form_ajax_subscriber:
class: Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber
arguments: ['@form_ajax_response_builder', '@renderer', '@string_translation']
arguments: ['@form_ajax_response_builder', '@string_translation']
tags:
- { name: event_subscriber }
route_enhancer.lazy_collector:
......
......@@ -195,7 +195,7 @@ function drupal_get_html_head($render = TRUE) {
$elements = _drupal_add_html_head();
\Drupal::moduleHandler()->alter('html_head', $elements);
if ($render) {
return drupal_render($elements);
return \Drupal::service('renderer')->renderPlain($elements);
}
else {
return $elements;
......
......@@ -164,15 +164,15 @@ protected function buildAttachmentsCommands(AjaxResponse $response, Request $req
$resource_commands = array();
if ($css_assets) {
$css_render_array = $this->cssCollectionRenderer->render($css_assets);
$resource_commands[] = new AddCssCommand($this->renderer->render($css_render_array));
$resource_commands[] = new AddCssCommand($this->renderer->renderPlain($css_render_array));
}
if ($js_assets_header) {
$js_header_render_array = $this->jsCollectionRenderer->render($js_assets_header);
$resource_commands[] = new PrependCommand('head', $this->renderer->render($js_header_render_array));
$resource_commands[] = new PrependCommand('head', $this->renderer->renderPlain($js_header_render_array));
}
if ($js_assets_footer) {
$js_footer_render_array = $this->jsCollectionRenderer->render($js_assets_footer);
$resource_commands[] = new AppendCommand('body', $this->renderer->render($js_footer_render_array));
$resource_commands[] = new AppendCommand('body', $this->renderer->renderPlain($js_footer_render_array));
}
foreach (array_reverse($resource_commands) as $resource_command) {
$response->addCommand($resource_command, TRUE);
......
......@@ -14,7 +14,6 @@
use Drupal\Core\Form\FormAjaxException;
use Drupal\Core\Form\FormAjaxResponseBuilderInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
......@@ -36,26 +35,16 @@ class FormAjaxSubscriber implements EventSubscriberInterface {
*/
protected $formAjaxResponseBuilder;
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a new FormAjaxSubscriber.
*
* @param \Drupal\Core\Form\FormAjaxResponseBuilderInterface $form_ajax_response_builder
* The form AJAX response builder.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation.
*/
public function __construct(FormAjaxResponseBuilderInterface $form_ajax_response_builder, RendererInterface $renderer, TranslationInterface $string_translation) {
public function __construct(FormAjaxResponseBuilderInterface $form_ajax_response_builder, TranslationInterface $string_translation) {
$this->formAjaxResponseBuilder = $form_ajax_response_builder;
$this->renderer = $renderer;
$this->stringTranslation = $string_translation;
}
......@@ -94,7 +83,7 @@ public function onException(GetResponseForExceptionEvent $event) {
$this->drupalSetMessage($this->t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', ['@size' => $this->formatSize($exception->getSize())]), 'error');
$response = new AjaxResponse();
$status_messages = ['#type' => 'status_messages'];
$response->addCommand(new ReplaceCommand(NULL, $this->renderer->renderRoot($status_messages)));
$response->addCommand(new ReplaceCommand(NULL, $status_messages));
$response->headers->set('X-Status-Code', 200);
$event->setResponse($response);
return;
......
......@@ -94,7 +94,7 @@ public static function preRenderActionsDropbutton(&$element, FormStateInterface
// Add this button to the corresponding dropbutton.
// @todo Change #type 'dropbutton' to be based on item-list.html.twig
// instead of links.html.twig to avoid this preemptive rendering.
$button = drupal_render($element[$key]);
$button = \Drupal::service('renderer')->renderPlain($element[$key]);
$dropbuttons[$dropbutton]['#links'][$key] = array(
'title' => $button,
);
......
......@@ -43,6 +43,13 @@ class BlockViewBuilderTest extends KernelTestBase {
*/
protected $controller;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* {@inheritdoc}
*/
......@@ -64,6 +71,8 @@ protected function setUp() {
$this->block->save();
$this->container->get('cache.render')->deleteAll();
$this->renderer = $this->container->get('renderer');
}
/**
......@@ -90,7 +99,7 @@ public function testBasicRendering() {
$expected[] = ' </div>';
$expected[] = '';
$expected_output = implode("\n", $expected);
$this->assertEqual(drupal_render($output), $expected_output);
$this->assertEqual($this->renderer->renderRoot($output), $expected_output);
// Reset the HTML IDs so that the next render is not affected.
Html::resetSeenIds();
......@@ -115,7 +124,7 @@ public function testBasicRendering() {
$expected[] = ' </div>';
$expected[] = '';
$expected_output = implode("\n", $expected);
$this->assertEqual(drupal_render($output), $expected_output);
$this->assertEqual($this->renderer->renderRoot($output), $expected_output);
}
/**
......@@ -144,7 +153,7 @@ public function testBlockViewBuilderCache() {
* @see ::testBlockViewBuilderCache()
*/
protected function verifyRenderCacheHandling() {
// Force a request via GET so we can get drupal_render() cache working.
// Force a request via GET so we can test the render cache.
$request = \Drupal::request();
$request_method = $request->server->get('REQUEST_METHOD');
$request->setMethod('GET');
......@@ -152,7 +161,7 @@ protected function verifyRenderCacheHandling() {
// Test that a cache entry is created.
$build = $this->getBlockRenderArray();
$cid = 'entity_view:block:test_block:en:core';
drupal_render($build);
$this->renderer->renderRoot($build);
$this->assertTrue($this->container->get('cache.render')->get($cid), 'The block render element has been cached.');
// Re-save the block and check that the cache entry has been deleted.
......@@ -166,7 +175,7 @@ protected function verifyRenderCacheHandling() {
// removes it.
$build['#block'] = $this->block;
drupal_render($build);
$this->renderer->renderRoot($build);
$this->assertTrue($this->container->get('cache.render')->get($cid), 'The block render element has been cached.');
$this->block->delete();
$this->assertFalse($this->container->get('cache.render')->get($cid), 'The block render cache entry has been cleared when the block was deleted.');
......@@ -181,17 +190,17 @@ protected function verifyRenderCacheHandling() {
public function testBlockViewBuilderAlter() {
// Establish baseline.
$build = $this->getBlockRenderArray();
$this->assertIdentical(drupal_render($build), 'Llamas &gt; unicorns!');
$this->assertIdentical($this->renderer->renderRoot($build), 'Llamas &gt; unicorns!');
// Enable the block view alter hook that adds a suffix, for basic testing.
\Drupal::state()->set('block_test_view_alter_suffix', TRUE);
Cache::invalidateTags($this->block->getCacheTags());
$build = $this->getBlockRenderArray();
$this->assertTrue(isset($build['#suffix']) && $build['#suffix'] === '<br>Goodbye!', 'A block with content is altered.');
$this->assertIdentical(drupal_render($build), 'Llamas &gt; unicorns!<br>Goodbye!');
$this->assertIdentical($this->renderer->renderRoot($build), 'Llamas &gt; unicorns!<br>Goodbye!');
\Drupal::state()->set('block_test_view_alter_suffix', FALSE);
// Force a request via GET so we can get drupal_render() cache working.
// Force a request via GET so we can test the render cache.
$request = \Drupal::request();
$request_method = $request->server->get('REQUEST_METHOD');
$request->setMethod('GET');
......@@ -209,7 +218,7 @@ public function testBlockViewBuilderAlter() {
$expected_keys = array_merge($default_keys, array($alter_add_key));
$build = $this->getBlockRenderArray();
$this->assertIdentical($expected_keys, $build['#cache']['keys'], 'An altered cacheable block has the expected cache keys.');
$this->assertIdentical(drupal_render($build), '');
$this->assertIdentical($this->renderer->renderRoot($build), '');
$cache_entry = $this->container->get('cache.render')->get($cid);
$this->assertTrue($cache_entry, 'The block render element has been cached with the expected cache ID.');
$expected_tags = array_merge($default_tags, ['rendered']);
......@@ -224,7 +233,7 @@ public function testBlockViewBuilderAlter() {
$build = $this->getBlockRenderArray();
sort($build['#cache']['tags']);
$this->assertIdentical($expected_tags, $build['#cache']['tags'], 'An altered cacheable block has the expected cache tags.');
$this->assertIdentical(drupal_render($build), '');
$this->assertIdentical($this->renderer->renderRoot($build), '');
$cache_entry = $this->container->get('cache.render')->get($cid);
$this->assertTrue($cache_entry, 'The block render element has been cached with the expected cache ID.');
$expected_tags = array_merge($default_tags, [$alter_add_tag, 'rendered']);
......@@ -236,8 +245,8 @@ public function testBlockViewBuilderAlter() {
// alter the eventual content.
\Drupal::state()->set('block_test_view_alter_append_pre_render_prefix', TRUE);
$build = $this->getBlockRenderArray();
$this->assertFalse(isset($build['#prefix']), 'The appended #pre_render callback has not yet run before calling drupal_render().');
$this->assertIdentical(drupal_render($build), 'Hiya!<br>');
$this->assertFalse(isset($build['#prefix']), 'The appended #pre_render callback has not yet run before rendering.');
$this->assertIdentical($this->renderer->renderRoot($build), 'Hiya!<br>');
$this->assertTrue(isset($build['#prefix']) && $build['#prefix'] === 'Hiya!<br>', 'A cached block without content is altered.');
// Restore the previous request method.
......
......@@ -84,7 +84,7 @@ public function testBlock() {
// Drupal\Core\Render\Renderer.
$request_stack = $this->container->get('request_stack');
$request_stack->push(new Request());
$this->container->get('renderer')->render($build);
$this->container->get('renderer')->renderRoot($build);
$request_stack->pop();
// Expected keys, contexts, and tags for the block.
......
......@@ -71,7 +71,7 @@ function book_theme() {
'render element' => 'book_menus',
),
'book_node_export_html' => array(
'variables' => array('node' => NULL, 'children' => NULL),
'variables' => array('node' => NULL, 'content' => NULL, 'children' => NULL),
),
);
}
......@@ -234,9 +234,9 @@ function book_node_view(array &$build, EntityInterface $node, EntityViewDisplayI
if (!$book_node->access()) {
return;
}
$book_navigation = array( '#theme' => 'book_navigation', '#book_link' => $node->book);
$build['book_navigation'] = array(
'#markup' => drupal_render($book_navigation),
'#theme' => 'book_navigation',
'#book_link' => $node->book,
'#weight' => 100,
// The book navigation is a listing of Node entities, so associate its
// list cache tag for correct invalidation.
......@@ -491,7 +491,6 @@ function template_preprocess_book_export_html(&$variables) {
function template_preprocess_book_node_export_html(&$variables) {
$variables['depth'] = $variables['node']->book['depth'];
$variables['title'] = SafeMarkup::checkPlain($variables['node']->label());
$variables['content'] = $variables['node']->rendered;
}
/**
......
......@@ -12,7 +12,7 @@ services:
arguments: ['@book.manager']
book.export:
class: Drupal\book\BookExport
arguments: ['@entity.manager', '@book.manager']
arguments: ['@entity.manager', '@book.manager', '@renderer']
book.outline_storage:
class: Drupal\book\BookOutlineStorage
arguments: ['@database']
......
......@@ -8,6 +8,7 @@
namespace Drupal\book;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
......@@ -118,7 +119,7 @@ protected function exportTraverse(array $tree, $callable) {
}
}
return drupal_render($build);
return $build;
}
/**
......@@ -139,10 +140,9 @@ protected function bookNodeExport(NodeInterface $node, $children = '') {
$build = $this->viewBuilder->view($node, 'print', NULL);
unset($build['#theme']);
// @todo Rendering should happen in the template using render().
$node->rendered = drupal_render($build);
return array(
'#theme' => 'book_node_export_html',
'#content' => $build,
'#node' => $node,
'#children' => $children,
);
......
......@@ -126,8 +126,7 @@ public function childrenLinks(array $book_link) {
}
if ($children) {
$elements = $this->bookManager->bookTreeOutput($children);
return drupal_render($elements);
return $this->bookManager->bookTreeOutput($children);
}
return '';
}
......
......@@ -10,6 +10,7 @@
use Drupal\book\BookExport;
use Drupal\book\BookManagerInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
use Drupal\node\NodeInterface;
......@@ -37,6 +38,13 @@ class BookController extends ControllerBase {
*/
protected $bookExport;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a BookController object.
*
......@@ -44,10 +52,13 @@ class BookController extends ControllerBase {
* The book manager.
* @param \Drupal\book\BookExport $bookExport
* The book export service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
*/
public function __construct(BookManagerInterface $bookManager, BookExport $bookExport) {
public function __construct(BookManagerInterface $bookManager, BookExport $bookExport, RendererInterface $renderer) {
$this->bookManager = $bookManager;
$this->bookExport = $bookExport;
$this->renderer = $renderer;
}
/**
......@@ -56,7 +67,8 @@ public function __construct(BookManagerInterface $bookManager, BookExport $bookE
public static function create(ContainerInterface $container) {
return new static(
$container->get('book.manager'),
$container->get('book.export')
$container->get('book.export'),
$container->get('renderer')
);
}
......@@ -154,7 +166,7 @@ public function bookExport($type, NodeInterface $node) {
}
$exported_book = $this->bookExport->{$method}($node);
return new Response(drupal_render($exported_book));
return new Response($this->renderer->renderRoot($exported_book));
}
}
......@@ -13,6 +13,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\RendererInterface;
use Drupal\editor\Plugin\EditorBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\editor\Entity\Editor as EditorEntity;
......@@ -55,6 +56,13 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
*/
protected $ckeditorPluginManager;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a Drupal\Component\Plugin\PluginBase object.
*
......@@ -70,12 +78,15 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface {
* The module handler to invoke hooks on.
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->ckeditorPluginManager = $ckeditor_plugin_manager;
$this->moduleHandler = $module_handler;
$this->languageManager = $language_manager;
$this->renderer = $renderer;
}
/**
......@@ -88,7 +99,8 @@ public static function create(ContainerInterface $container, array $configuratio
$plugin_definition,
$container->get('plugin.manager.ckeditor.plugin'),
$container->get('module_handler'),
$container->get('language_manager')
$container->get('language_manager'),
$container->get('renderer')
);
}
......@@ -145,7 +157,7 @@ public function settingsForm(array $form, FormStateInterface $form_state, Editor
'library' => array('ckeditor/drupal.ckeditor.admin'),
'drupalSettings' => [
'ckeditor' => [
'toolbarAdmin' => drupal_render($ckeditor_settings_toolbar),
'toolbarAdmin' => $this->renderer->renderPlain($ckeditor_settings_toolbar),
],
],
),
......
......@@ -462,7 +462,7 @@ function comment_node_update_index(EntityInterface $node, $langcode) {
}
}
}
return drupal_render($build);
return \Drupal::service('renderer')->renderPlain($build);
}
/**
......
......@@ -28,7 +28,7 @@ class UnpublishByKeywordComment extends ConfigurableActionBase {
*/
public function execute($comment = NULL) {
$build = comment_view($comment);
$text = drupal_render($build);
$text = \Drupal::service('renderer')->renderPlain($build);
foreach ($this->configuration['keywords'] as $keyword) {
if (strpos($text, $keyword) !== FALSE) {
$comment->setPublished(FALSE);
......
......@@ -57,6 +57,9 @@ protected function setUp() {
* Tests the bubbling of cache tags.
*/
public function testCacheTags() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
// Create the entity that will be commented upon.
$commented_entity = entity_create('entity_test', array('name' => $this->randomMachineName()));
$commented_entity->save();
......@@ -65,11 +68,16 @@ public function testCacheTags() {
$build = \Drupal::entityManager()
->getViewBuilder('entity_test')
->view($commented_entity);
drupal_render($build);
$renderer->renderRoot($build);
$expected_cache_tags = array(
'entity_test_view',
'entity_test:' . $commented_entity->id(),
'comment_list',
'config:core.entity_form_display.comment.comment.default',
'config:field.field.comment.comment.comment_body',
'config:field.field.entity_test.entity_test.comment',
'config:field.storage.comment.comment_body',
'config:user.settings',
);
sort($expected_cache_tags);
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags before it has comments.');
......@@ -102,7 +110,7 @@ public function testCacheTags() {
$build = \Drupal::entityManager()
->getViewBuilder('entity_test')
->view($commented_entity);
drupal_render($build);
$renderer->renderRoot($build);
$expected_cache_tags = array(
'entity_test_view',
'entity_test:' . $commented_entity->id(),
......@@ -112,6 +120,11 @@ public function testCacheTags() {
'config:filter.format.plain_text',
'user_view',
'user:2',
'config:core.entity_form_display.comment.comment.default',
'config:field.field.comment.comment.comment_body',
'config:field.field.entity_test.entity_test.comment',
'config:field.storage.comment.comment_body',
'config:user.settings',
);
sort($expected_cache_tags);
$this->assertEqual($build['#cache']['tags'], $expected_cache_tags, 'The test entity has the expected cache tags when it has comments.');
......
......@@ -142,7 +142,7 @@ public function testUsername() {
$account_switcher->switchTo($this->adminUser);
$executable = Views::getView($view_id);
$build = $executable->preview();
$this->setRawContent($renderer->render($build));
$this->setRawContent($renderer->renderRoot($build));
$this->verbose($this->getRawContent());
$this->assertLink('My comment title');
......@@ -155,7 +155,7 @@ public function testUsername() {
$executable->storage->invalidateCaches();
$build = $executable->preview();
$this->setRawContent($renderer->render($build));
$this->setRawContent($renderer->renderRoot($build));
// No access to user-profiles, so shouldn't be able to see links.
$this->assertNoLink($this->adminUser->label());
......
......@@ -21,6 +21,7 @@
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Drupal\Core\Config\StorageComparer;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Url;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -100,6 +101,13 @@ class ConfigSync extends FormBase {
*/
protected $moduleInstaller;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs the object.
*
......@@ -123,8 +131,10 @@ class ConfigSync extends FormBase {
* The module installer.
* @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
* The theme handler.
* @param \Drupal\Core\Render\RendererInterface
* The renderer.
*/
public function __construct(StorageInterface $staging_storage, StorageInterface $active_storage, StorageInterface $snapshot_storage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler) {
public function __construct(StorageInterface $staging_storage, StorageInterface $active_storage, StorageInterface $snapshot_storage, LockBackendInterface $lock, EventDispatcherInterface $event_dispatcher, ConfigManagerInterface $config_manager, TypedConfigManagerInterface $typed_config, ModuleHandlerInterface $module_handler, ModuleInstallerInterface $module_installer, ThemeHandlerInterface $theme_handler, RendererInterface $renderer) {
$this->stagingStorage = $staging_storage;
$this->activeStorage = $active_storage;
$this->snapshotStorage = $snapshot_storage;
......@@ -135,6 +145,7 @@ public function __construct(StorageInterface $staging_storage, StorageInterface
$this->moduleHandler = $module_handler;
$this->moduleInstaller = $module_installer;
$this->themeHandler = $theme_handler;
$this->renderer = $renderer;
}
/**
......@@ -151,7 +162,8 @@ public static function create(ContainerInterface $container) {
$container->get('config.typed'),
$container->get('module_handler'),
$container->get('module_installer'),
$container->get('theme_handler')
$container->get('theme_handler'),
$container->get('renderer')
);
}
......@@ -209,7 +221,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#theme' => 'item_list',
'#items' => $change_list,
);
$change_list_html = drupal_render($change_list_render);
$change_list_html = $this->renderer->renderPlain($change_list_render);
drupal_set_message($this->t('The following items in your active configuration have changes since the last import that may be lost on the next import. !changes', array('!changes' => $change_list_html)), 'warning');
}
}
......
......@@ -65,9 +65,9 @@ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = N
$build[$key]['#label_display'] = 'hidden';
}
}
$build = array(
'#markup' => MailFormatHelper::htmlToText(drupal_render($build)),
);
$build['#post_render'][] = function ($html, array $elements) {
return MailFormatHelper::htmlToText($html);
};
}
return $build;
}
......
......@@ -44,7 +44,7 @@ public function render(Request $request) {
'#type' => 'contextual_links',
'#contextual_links' => _contextual_id_to_links($id),
);
$rendered[$id] = drupal_render($element);
$rendered[$id] = $this->container->get('renderer')->renderRoot($element);
}
return new JsonResponse($rendered);
......
......@@ -644,7 +644,7 @@ protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) {
$entity = entity_load('entity_test', $id);
$display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
$build = $display->build($entity);
$output = drupal_render($build);
$output = \Drupal::service('renderer')->renderRoot($build);
$this->setRawContent($output);
$this->verbose($output);
}
......
......@@ -90,10 +90,11 @@ public function render() {
$results = array();
foreach ($sets as $records) {
foreach ($records as $values) {
$results[$values->{$id_field_alias}] = $this->view->rowPlugin->render($values);
// Sanitize HTML, remove line breaks and extra whitespace.
$output = $this->view->rowPlugin->render($values);
$output = drupal_render($output);
$results[$values->{$id_field_alias}] = Xss::filterAdmin(preg_replace('/\s\s+/', ' ', str_replace("\n", '', $output)));
$results[$values->{$id_field_alias}]['#post_render'][] = function ($html, array $elements) {
return Xss::filterAdmin(preg_replace('/\s\s+/', ' ', str_replace("\n", '', $html)));
};
}
}
return $results;
......
......@@ -121,7 +121,7 @@ function field_help($route_name, RouteMatchInterface $route_match) {
'#theme' => 'item_list',
'#items' => $items,
);
$output .= drupal_render($item_list);
$output .= \Drupal::service('renderer')->renderPlain($item_list);
$output .= '</dd>';
}
......
......@@ -114,7 +114,7 @@ function testBooleanField() {
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->setRawContent(drupal_render($content));
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertRaw('<div class="field-item">' . $on . '</div>');
// Test if we can change the on label.
......
......@@ -102,7 +102,7 @@ function testEmailField() {
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->getEntityTypeId(), $entity->bundle(), 'full');
$content = $display->build($entity);
$this->setRawContent(drupal_render($content));
$this->setRawContent(\Drupal::service('renderer')->renderRoot($content));
$this->assertLinkByHref('mailto:test@example.com');
}
......
......@@ -179,6 +179,8 @@ public function testIdFormatter() {
* Tests the entity formatter.
*/
public function testEntityFormatter() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
$formatter = 'entity_reference_entity_view';
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
......@@ -196,7 +198,7 @@ public function testEntityFormatter() {
</div>
</div>
';
drupal_render($build[0]);
$renderer->renderRoot($build[0]);
$this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field_1 . $expected_rendered_body_field_1, sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$expected_cache_tags = Cache::mergeTags(
\Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTags(),
......@@ -206,7 +208,7 @@ public function testEntityFormatter() {
$this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter)));
// Test the second field item.
drupal_render($build[1]);