core/modules/ckeditor/src/Plugin/Editor/CKEditor.php | 18 +++++++++++++++--- .../EntityReference/EntityReferenceFormatterTest.php | 8 +++++--- .../simpletest/src/Tests/KernelTestBaseTest.php | 5 +++-- .../views/src/Plugin/views/style/StylePluginBase.php | 2 +- .../src/Tests/Handler/FieldFieldAccessTestBase.php | 4 ++-- core/modules/views/src/Tests/ViewRenderTest.php | 2 +- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php index 949c8e5..0e237b1 100644 --- a/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php +++ b/core/modules/ckeditor/src/Plugin/Editor/CKEditor.php @@ -13,6 +13,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Render\Element; +use Drupal\Core\Render\RendererInterface; use Drupal\editor\Plugin\EditorBase; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\editor\Entity\Editor as EditorEntity; @@ -56,6 +57,13 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface { protected $ckeditorPluginManager; /** + * The renderer. + * + * @var \Drupal\Core\Render\RendererInterface + */ + protected $renderer; + + /** * Constructs a Drupal\Component\Plugin\PluginBase object. * * @param array $configuration @@ -70,12 +78,15 @@ class CKEditor extends EditorBase implements ContainerFactoryPluginInterface { * The module handler to invoke hooks on. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. + * @param \Drupal\Core\Render\RendererInterface $renderer + * The renderer. */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager) { + public function __construct(array $configuration, $plugin_id, $plugin_definition, CKEditorPluginManager $ckeditor_plugin_manager, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, RendererInterface $renderer) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->ckeditorPluginManager = $ckeditor_plugin_manager; $this->moduleHandler = $module_handler; $this->languageManager = $language_manager; + $this->renderer = $renderer; } /** @@ -88,7 +99,8 @@ public static function create(ContainerInterface $container, array $configuratio $plugin_definition, $container->get('plugin.manager.ckeditor.plugin'), $container->get('module_handler'), - $container->get('language_manager') + $container->get('language_manager'), + $container->get('renderer') ); } @@ -145,7 +157,7 @@ public function settingsForm(array $form, FormStateInterface $form_state, Editor 'library' => array('ckeditor/drupal.ckeditor.admin'), 'drupalSettings' => [ 'ckeditor' => [ - 'toolbarAdmin' => drupal_render($ckeditor_settings_toolbar), + 'toolbarAdmin' => $this->renderer->renderPlain($ckeditor_settings_toolbar), ], ], ), diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php index 52fdc08..022ec5c 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceFormatterTest.php @@ -179,6 +179,7 @@ public function testIdFormatter() { * Tests the entity formatter. */ public function testEntityFormatter() { + $renderer = $this->container->get('renderer'); $formatter = 'entity_reference_entity_view'; $build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter); @@ -196,7 +197,7 @@ public function testEntityFormatter() { '; - drupal_render($build[0]); + $renderer->renderRoot($build[0]); $this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field_1 . $expected_rendered_body_field_1, sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter)); $expected_cache_tags = Cache::mergeTags( \Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTags(), @@ -206,7 +207,7 @@ public function testEntityFormatter() { $this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter))); // Test the second field item. - drupal_render($build[1]); + $renderer->renderRoot($build[1]); $this->assertEqual($build[1]['#markup'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter)); } @@ -214,6 +215,7 @@ public function testEntityFormatter() { * Tests the label formatter. */ public function testLabelFormatter() { + $renderer = $this->container->get('renderer'); $formatter = 'entity_reference_label'; // The 'link' settings is TRUE by default. @@ -237,7 +239,7 @@ public function testLabelFormatter() { 'tags' => $this->referencedEntity->getCacheTags(), ), ); - $this->assertEqual(drupal_render($build[0]), drupal_render($expected_item_1), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter)); + $this->assertEqual($renderer->renderRoot($build[0]), $renderer->renderRoot($expected_item_1), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter)); $this->assertEqual(CacheableMetadata::createFromRenderArray($build[0]), CacheableMetadata::createFromRenderArray($expected_item_1)); // The second referenced entity is "autocreated", therefore not saved and diff --git a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php index 2e8a8c2..4ae7ef0 100644 --- a/core/modules/simpletest/src/Tests/KernelTestBaseTest.php +++ b/core/modules/simpletest/src/Tests/KernelTestBaseTest.php @@ -284,6 +284,7 @@ function testEnableModulesFixedList() { * Tests that _theme() works right after loading a module. */ function testEnableModulesTheme() { + $renderer = $this->container->get('renderer'); $original_element = $element = array( '#type' => 'container', '#markup' => 'Foo', @@ -291,11 +292,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/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/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/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); }