From 75d943a0af4a3657373ab64509f1b476f5426526 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Mon, 4 Mar 2024 11:02:33 +0000 Subject: [PATCH] Issue #2511308 by dimitriskr, ankithashetty, smustgrave, quietone, Wim Leers: Rename RendererInterface::renderPlain() to ::renderInIsolation() --- core/includes/install.core.inc | 2 +- core/includes/install.inc | 2 +- .../Action/Plugin/Action/MessageAction.php | 2 +- ...lyRenderingControllerWrapperSubscriber.php | 2 +- .../Core/Installer/Form/SiteSettingsForm.php | 2 +- .../Drupal/Core/Render/Element/Actions.php | 2 +- .../HtmlResponseAttachmentsProcessor.php | 2 +- core/lib/Drupal/Core/Render/Renderer.php | 16 +++++++--- .../Drupal/Core/Render/RendererInterface.php | 12 +++++-- ...namicPluginConfigWithCsrfTokenUrlTrait.php | 2 +- core/modules/comment/comment.module | 2 +- .../Action/UnpublishByKeywordComment.php | 2 +- .../tests/src/Kernel/CommentOrphanTest.php | 6 ++-- core/modules/config/src/Form/ConfigSync.php | 2 +- .../ConfigTranslationController.php | 2 +- core/modules/contact/contact.module | 4 +-- core/modules/field/field.module | 2 +- .../tests/src/Kernel/FieldDisplayTest.php | 2 +- core/modules/file/file.module | 6 ++-- core/modules/file/src/Element/ManagedFile.php | 2 +- .../Plugin/Field/FieldWidget/FileWidget.php | 2 +- core/modules/filter/filter.module | 2 +- core/modules/forum/forum.module | 2 +- .../Plugin/HelpSection/HelpTopicSection.php | 4 +-- .../src/Functional/HelpTopicsSyntaxTest.php | 2 +- .../Plugin/Field/FieldWidget/ImageWidget.php | 2 +- .../src/FormErrorHandler.php | 2 +- .../tests/src/Unit/FormErrorHandlerTest.php | 4 +-- .../src/Controller/MediaFilterController.php | 2 +- .../media/src/Plugin/Filter/MediaEmbed.php | 2 +- .../media_library/src/Form/FileUploadForm.php | 2 +- .../node/src/Controller/NodeController.php | 2 +- .../node/src/Plugin/Search/NodeSearch.php | 6 ++-- .../src/Functional/NodeRevisionsUiTest.php | 2 +- .../tests/src/Functional/NodeRssCacheTest.php | 2 +- .../tests/src/Kernel/NodeViewBuilderTest.php | 4 +-- .../tests/src/Kernel/SearchExcerptTest.php | 2 +- core/modules/system/system.install | 2 +- core/modules/system/system.tokens.inc | 2 +- .../batch_test/batch_test.callbacks.inc | 2 +- .../mail_html_test/mail_html_test.module | 2 +- .../EventSubscriber/ThemeTestSubscriber.php | 2 +- .../Functional/Form/ElementsLabelsTest.php | 2 +- .../System/SitesDirectoryHardeningTest.php | 2 +- .../src/Functional/Theme/TwigTransTest.php | 2 +- core/modules/taxonomy/taxonomy.tokens.inc | 2 +- .../tests/src/Kernel/TermKernelTest.php | 2 +- core/modules/text/src/TextProcessed.php | 2 +- core/modules/tour/src/TourViewBuilder.php | 2 +- .../Plugin/tour/tip/TipPluginImageLegacy.php | 2 +- .../src/Controller/UpdateController.php | 2 +- .../update/src/Form/UpdateManagerUpdate.php | 2 +- core/modules/update/update.module | 2 +- .../src/Functional/Views/AccessRoleTest.php | 4 +-- .../src/Kernel/Views/AccessPermissionTest.php | 4 +-- .../ViewsSelection.php | 2 +- .../views/src/Plugin/views/PluginBase.php | 4 +-- .../Plugin/views/style/StylePluginBase.php | 4 +-- .../views_test_data.views_execution.inc | 2 +- .../src/Functional/Plugin/CacheTagTest.php | 12 +++---- .../Handler/FieldRenderedEntityTest.php | 4 +-- .../src/Kernel/Handler/SortRandomTest.php | 4 +-- .../views/tests/src/Kernel/ModuleTest.php | 10 +++--- .../tests/src/Kernel/Plugin/CacheTest.php | 2 +- .../src/Kernel/Plugin/PagerKernelTest.php | 4 +-- .../Unit/Plugin/field/FieldPluginBaseTest.php | 6 ++-- .../Core/Asset/AttachedAssetsTest.php | 32 +++++++++---------- .../KernelTests/Core/Render/RenderTest.php | 11 +++++++ .../Core/Render/RendererRecursionTest.php | 8 ++--- .../Drupal/Tests/Core/Render/RendererTest.php | 2 +- 70 files changed, 146 insertions(+), 119 deletions(-) diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index a99f19c7bf5f..9857c66ff2dd 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -2299,7 +2299,7 @@ function install_display_requirements($install_state, $requirements) { 'description' => $requirement['description'], ], ]; - $failures[] = \Drupal::service('renderer')->renderPlain($render_array); + $failures[] = \Drupal::service('renderer')->renderInIsolation($render_array); } } if (!empty($failures)) { diff --git a/core/includes/install.inc b/core/includes/install.inc index 60d8272c8b9a..9c8a859768a2 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -374,7 +374,7 @@ function drupal_verify_profile($install_state) { $build['#items'][] = ['#markup' => '<span class="admin-missing">' . Unicode::ucfirst($module) . '</span>']; } - $modules_list = \Drupal::service('renderer')->renderPlain($build); + $modules_list = \Drupal::service('renderer')->renderInIsolation($build); $requirements['required_modules'] = [ 'title' => t('Required modules'), 'value' => t('Required modules not found.'), diff --git a/core/lib/Drupal/Core/Action/Plugin/Action/MessageAction.php b/core/lib/Drupal/Core/Action/Plugin/Action/MessageAction.php index 7a9dd005f60d..a498d2dccef3 100644 --- a/core/lib/Drupal/Core/Action/Plugin/Action/MessageAction.php +++ b/core/lib/Drupal/Core/Action/Plugin/Action/MessageAction.php @@ -89,7 +89,7 @@ public function execute($entity = NULL) { ]; // @todo Fix in https://www.drupal.org/node/2577827 - $this->messenger->addStatus($this->renderer->renderPlain($build)); + $this->messenger->addStatus($this->renderer->renderInIsolation($build)); } /** diff --git a/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php index c6fa8d2ba807..581133a87be8 100644 --- a/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php @@ -33,7 +33,7 @@ * * If the render context is empty, then the controller either did not do any * rendering at all, or used the RendererInterface::renderRoot() or - * ::renderPlain() methods. In that case, no bubbleable metadata is lost. + * ::renderInIsolation() methods. In that case, no bubbleable metadata is lost. * * If the render context is not empty, then the controller did use * RendererInterface::render(), and bubbleable metadata was collected. diff --git a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php index 0a5ffc02ab6b..46cf9e2084c2 100644 --- a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php @@ -195,7 +195,7 @@ protected function getDatabaseErrors(array $database, $settings_file) { // These are generic errors, so we do not have any specific key of the // database connection array to attach them to; therefore, we just put // them in the error array with standard numeric keys. - $form_errors[$database['driver'] . '][0'] = $this->renderer->renderPlain($error_message); + $form_errors[$database['driver'] . '][0'] = $this->renderer->renderInIsolation($error_message); } return $form_errors; diff --git a/core/lib/Drupal/Core/Render/Element/Actions.php b/core/lib/Drupal/Core/Render/Element/Actions.php index 262b3db0df47..2b9b7cd5926d 100644 --- a/core/lib/Drupal/Core/Render/Element/Actions.php +++ b/core/lib/Drupal/Core/Render/Element/Actions.php @@ -100,7 +100,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::service('renderer')->renderPlain($element[$key]); + $button = \Drupal::service('renderer')->renderInIsolation($element[$key]); $dropbuttons[$dropbutton]['#links'][$key] = [ 'title' => $button, ]; diff --git a/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php b/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php index a768b0b8978c..9cb8e0a848fb 100644 --- a/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php +++ b/core/lib/Drupal/Core/Render/HtmlResponseAttachmentsProcessor.php @@ -354,7 +354,7 @@ protected function renderHtmlResponseAttachmentPlaceholders(HtmlResponse $respon $content = $response->getContent(); foreach ($placeholders as $type => $placeholder) { if (isset($variables[$type])) { - $content = str_replace($placeholder, $this->renderer->renderPlain($variables[$type]), $content); + $content = str_replace($placeholder, $this->renderer->renderInIsolation($variables[$type]), $content); } } $response->setContent($content); diff --git a/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php index 9ad0d34d7894..3ce49244de1f 100644 --- a/core/lib/Drupal/Core/Render/Renderer.php +++ b/core/lib/Drupal/Core/Render/Renderer.php @@ -160,12 +160,20 @@ public function renderRoot(&$elements) { /** * {@inheritdoc} */ - public function renderPlain(&$elements) { + public function renderInIsolation(&$elements) { return $this->executeInRenderContext(new RenderContext(), function () use (&$elements) { return $this->render($elements, TRUE); }); } + /** + * {@inheritdoc} + */ + public function renderPlain(&$elements) { + @trigger_error('Renderer::renderPlain() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Instead, you should use ::renderInIsolation(). See https://www.drupal.org/node/3407994', E_USER_DEPRECATED); + return $this->renderInIsolation($elements); + } + /** * Renders a placeholder into markup. * @@ -180,7 +188,7 @@ protected function doRenderPlaceholder(array &$placeholder_element): MarkupInter $placeholder_element['#create_placeholder'] = FALSE; // Render the placeholder into markup. - $markup = $this->renderPlain($placeholder_element); + $markup = $this->renderInIsolation($placeholder_element); return $markup; } @@ -272,7 +280,7 @@ protected function doRender(&$elements, $is_root_call = FALSE) { // Abort, but bubble new cache metadata from the access result. $context = $this->getCurrentRenderContext(); if (!isset($context)) { - throw new \LogicException("Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead."); + throw new \LogicException("Render context is empty, because render() was called outside of a renderRoot() or renderInIsolation() call. Use renderInIsolation()/renderRoot() or #lazy_builder/#pre_render instead."); } $context->push(new BubbleableMetadata()); $context->update($elements); @@ -292,7 +300,7 @@ protected function doRender(&$elements, $is_root_call = FALSE) { $context = $this->getCurrentRenderContext(); if (!isset($context)) { - throw new \LogicException("Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead."); + throw new \LogicException("Render context is empty, because render() was called outside of a renderRoot() or renderInIsolation() call. Use renderInIsolation()/renderRoot() or #lazy_builder/#pre_render instead."); } $context->push(new BubbleableMetadata()); diff --git a/core/lib/Drupal/Core/Render/RendererInterface.php b/core/lib/Drupal/Core/Render/RendererInterface.php index 1344c5631b9b..310e4fcc836a 100644 --- a/core/lib/Drupal/Core/Render/RendererInterface.php +++ b/core/lib/Drupal/Core/Render/RendererInterface.php @@ -59,6 +59,14 @@ public function renderRoot(&$elements); * @see \Drupal\Core\Render\RendererInterface::renderRoot() * @see \Drupal\Core\Render\RendererInterface::render() */ + public function renderInIsolation(&$elements); + + /** + * @deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use + * \Drupal\Core\Render\RendererInterface::renderInIsolation() instead. + * + * @see https://www.drupal.org/node/3407994 + */ public function renderPlain(&$elements); /** @@ -320,7 +328,7 @@ public function renderPlaceholder($placeholder, array $elements); * * @throws \LogicException * When called outside of a render context (i.e. outside of a renderRoot(), - * renderPlain() or executeInRenderContext() call). + * renderInIsolation() or executeInRenderContext() call). * @throws \Exception * If a #pre_render callback throws an exception, it is caught to mark the * renderer as no longer being in a root render call, if any. Then the @@ -350,7 +358,7 @@ public function hasRenderContext(); * Executes a callable within a render context. * * Only for very advanced use cases. Prefer using ::renderRoot() and - * ::renderPlain() instead. + * ::renderInIsolation() instead. * * All rendering must happen within a render context. Within a render context, * all bubbleable metadata is bubbled and hence tracked. Outside of a render diff --git a/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/DynamicPluginConfigWithCsrfTokenUrlTrait.php b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/DynamicPluginConfigWithCsrfTokenUrlTrait.php index 997a984df16c..6a5dbd0f4a5f 100644 --- a/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/DynamicPluginConfigWithCsrfTokenUrlTrait.php +++ b/core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/DynamicPluginConfigWithCsrfTokenUrlTrait.php @@ -46,7 +46,7 @@ private static function getUrlWithReplacedCsrfTokenPlaceholder(Url $url): string '#plain_text' => $generated_url->getGeneratedUrl(), ]; $generated_url->applyTo($url_with_csrf_token_placeholder); - return (string) \Drupal::service('renderer')->renderPlain($url_with_csrf_token_placeholder); + return (string) \Drupal::service('renderer')->renderInIsolation($url_with_csrf_token_placeholder); } } diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 2f86bb89758a..0928695ed156 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -403,7 +403,7 @@ function comment_node_update_index(EntityInterface $node) { } } } - return \Drupal::service('renderer')->renderPlain($build); + return \Drupal::service('renderer')->renderInIsolation($build); } /** diff --git a/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php b/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php index 891ae2563144..fd26bbc58e4c 100644 --- a/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php +++ b/core/modules/comment/src/Plugin/Action/UnpublishByKeywordComment.php @@ -76,7 +76,7 @@ public static function create(ContainerInterface $container, array $configuratio */ public function execute($comment = NULL) { $build = $this->viewBuilder->view($comment); - $text = $this->renderer->renderPlain($build); + $text = $this->renderer->renderInIsolation($build); foreach ($this->configuration['keywords'] as $keyword) { if (str_contains($text, $keyword)) { $comment->setUnpublished(); diff --git a/core/modules/comment/tests/src/Kernel/CommentOrphanTest.php b/core/modules/comment/tests/src/Kernel/CommentOrphanTest.php index 492eb6ffc9cc..a7c3c2c9f622 100644 --- a/core/modules/comment/tests/src/Kernel/CommentOrphanTest.php +++ b/core/modules/comment/tests/src/Kernel/CommentOrphanTest.php @@ -98,7 +98,7 @@ public function testOrphan($property) { $comments = $comment_storage->loadMultiple(); foreach ($comments as $comment) { $built = $this->buildEntityView($comment, 'full', NULL); - $renderer->renderPlain($built); + $renderer->renderInIsolation($built); } // Make comment 2 an orphan by setting the property to an invalid value. @@ -113,12 +113,12 @@ public function testOrphan($property) { $comments = $comment_storage->loadMultiple(); foreach ($comments as $comment) { $built = $this->buildEntityView($comment, 'full', NULL); - $renderer->renderPlain($built); + $renderer->renderInIsolation($built); } $node = $node_storage->load($node->id()); $built = $this->buildEntityView($node, 'full', NULL); - $renderer->renderPlain($built); + $renderer->renderInIsolation($built); } /** diff --git a/core/modules/config/src/Form/ConfigSync.php b/core/modules/config/src/Form/ConfigSync.php index af39f3cea2ae..c98c23e1bb39 100644 --- a/core/modules/config/src/Form/ConfigSync.php +++ b/core/modules/config/src/Form/ConfigSync.php @@ -266,7 +266,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#items' => $change_list, ], ]; - $this->messenger()->addWarning($this->renderer->renderPlain($message)); + $this->messenger()->addWarning($this->renderer->renderInIsolation($message)); } } diff --git a/core/modules/config_translation/src/Controller/ConfigTranslationController.php b/core/modules/config_translation/src/Controller/ConfigTranslationController.php index da17189c6daa..55be906a69de 100644 --- a/core/modules/config_translation/src/Controller/ConfigTranslationController.php +++ b/core/modules/config_translation/src/Controller/ConfigTranslationController.php @@ -163,7 +163,7 @@ public function itemPage(Request $request, RouteMatchInterface $route_match, $pl '#items' => $items, ], ]; - $this->messenger()->addWarning($this->renderer->renderPlain($message)); + $this->messenger()->addWarning($this->renderer->renderInIsolation($message)); $original_langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED; $operations_access = FALSE; diff --git a/core/modules/contact/contact.module b/core/modules/contact/contact.module index 271a01342e15..e1d8b6196a52 100644 --- a/core/modules/contact/contact.module +++ b/core/modules/contact/contact.module @@ -144,7 +144,7 @@ function contact_mail($key, &$message, $params) { $build = \Drupal::entityTypeManager() ->getViewBuilder('contact_message') ->view($contact_message, 'mail'); - $message['body'][] = \Drupal::service('renderer')->renderPlain($build); + $message['body'][] = \Drupal::service('renderer')->renderInIsolation($build); break; case 'page_autoreply': @@ -165,7 +165,7 @@ function contact_mail($key, &$message, $params) { $build = \Drupal::entityTypeManager() ->getViewBuilder('contact_message') ->view($contact_message, 'mail'); - $message['body'][] = \Drupal::service('renderer')->renderPlain($build); + $message['body'][] = \Drupal::service('renderer')->renderInIsolation($build); break; } } diff --git a/core/modules/field/field.module b/core/modules/field/field.module index 534d0718f125..f68daf91e3e3 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -127,7 +127,7 @@ function field_help($route_name, RouteMatchInterface $route_match) { '#theme' => 'item_list', '#items' => $items, ]; - $output .= \Drupal::service('renderer')->renderPlain($item_list); + $output .= \Drupal::service('renderer')->renderInIsolation($item_list); $output .= '</dd>'; } diff --git a/core/modules/field/tests/src/Kernel/FieldDisplayTest.php b/core/modules/field/tests/src/Kernel/FieldDisplayTest.php index 14d568f4fed9..c6972a420aa3 100644 --- a/core/modules/field/tests/src/Kernel/FieldDisplayTest.php +++ b/core/modules/field/tests/src/Kernel/FieldDisplayTest.php @@ -115,7 +115,7 @@ public function testFieldVisualHidden() { $build = $this->display->build($entity); $renderer = \Drupal::service('renderer'); - $content = (string) $renderer->renderPlain($build); + $content = (string) $renderer->renderInIsolation($build); $this->setRawContent($content); $css_selector_converter = new CssSelectorConverter(); diff --git a/core/modules/file/file.module b/core/modules/file/file.module index b97f178a8a42..525c8b15d5c4 100644 --- a/core/modules/file/file.module +++ b/core/modules/file/file.module @@ -549,7 +549,7 @@ function _file_save_upload_from_form(array $element, FormStateInterface $form_st '#items' => $errors_new, ], ]; - $error_message = \Drupal::service('renderer')->renderPlain($render_array); + $error_message = \Drupal::service('renderer')->renderInIsolation($render_array); } else { $error_message = reset($errors_new); @@ -679,7 +679,7 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL // @todo Add support for render arrays in // \Drupal\Core\Messenger\MessengerInterface::addMessage()? // @see https://www.drupal.org/node/2505497. - \Drupal::messenger()->addError($renderer->renderPlain($message)); + \Drupal::messenger()->addError($renderer->renderInIsolation($message)); $files[$i] = FALSE; continue; } @@ -1136,7 +1136,7 @@ function template_preprocess_file_widget_multiple(&$variables) { // Save the uploading row for last. if (empty($widget['#files'])) { $widget['#title'] = $element['#file_upload_title']; - $widget['#description'] = \Drupal::service('renderer')->renderPlain($element['#file_upload_description']); + $widget['#description'] = \Drupal::service('renderer')->renderInIsolation($element['#file_upload_description']); continue; } diff --git a/core/modules/file/src/Element/ManagedFile.php b/core/modules/file/src/Element/ManagedFile.php index a27740b6b86e..b15987543ce9 100644 --- a/core/modules/file/src/Element/ManagedFile.php +++ b/core/modules/file/src/Element/ManagedFile.php @@ -337,7 +337,7 @@ public static function processManagedFile(&$element, FormStateInterface $form_st if ($element['#multiple']) { $element['file_' . $delta]['selected'] = [ '#type' => 'checkbox', - '#title' => \Drupal::service('renderer')->renderPlain($file_link), + '#title' => \Drupal::service('renderer')->renderInIsolation($file_link), ]; } else { diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index 2edfae34c333..62db3ddf1a43 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -264,7 +264,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen '#upload_validators' => $element['#upload_validators'], '#cardinality' => $cardinality, ]; - $element['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help); + $element['#description'] = \Drupal::service('renderer')->renderInIsolation($file_upload_help); $element['#multiple'] = $cardinality != 1 ? TRUE : FALSE; if ($cardinality != 1 && $cardinality != -1) { $element['#element_validate'] = [[static::class, 'validateMultipleCount']]; diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index c6cae99e5a8b..061933dc96aa 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -307,7 +307,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $filter_types_to '#filter_types_to_skip' => $filter_types_to_skip, '#langcode' => $langcode, ]; - return \Drupal::service('renderer')->renderPlain($build); + return \Drupal::service('renderer')->renderInIsolation($build); } /** diff --git a/core/modules/forum/forum.module b/core/modules/forum/forum.module index b6fa665156d4..6ac1986835dc 100644 --- a/core/modules/forum/forum.module +++ b/core/modules/forum/forum.module @@ -78,7 +78,7 @@ function forum_help($route_name, RouteMatchInterface $route_match) { 'class' => ['more-link'], ], ]; - $output .= \Drupal::service('renderer')->renderPlain($container); + $output .= \Drupal::service('renderer')->renderInIsolation($container); return $output; case 'forum.add_container': diff --git a/core/modules/help/src/Plugin/HelpSection/HelpTopicSection.php b/core/modules/help/src/Plugin/HelpSection/HelpTopicSection.php index e2395f56fb67..e918621b7115 100644 --- a/core/modules/help/src/Plugin/HelpSection/HelpTopicSection.php +++ b/core/modules/help/src/Plugin/HelpSection/HelpTopicSection.php @@ -189,7 +189,7 @@ public function renderTopicForSearch($topic_id, LanguageInterface $language) { '#markup' => $plugin->getLabel(), ], ]; - $topic['title'] = $this->renderer->renderPlain($title_build); + $topic['title'] = $this->renderer->renderInIsolation($title_build); $cacheable_metadata = CacheableMetadata::createFromRenderArray($title_build); // Render the body in this language. For this, we need to set up a render @@ -199,7 +199,7 @@ public function renderTopicForSearch($topic_id, LanguageInterface $language) { $build = [ 'body' => $this->renderer->executeInRenderContext($context, [$plugin, 'getBody']), ]; - $topic['text'] = $this->renderer->renderPlain($build); + $topic['text'] = $this->renderer->renderInIsolation($build); $cacheable_metadata->addCacheableDependency(CacheableMetadata::createFromRenderArray($build)); $cacheable_metadata->addCacheableDependency($plugin); if (!$context->isEmpty()) { diff --git a/core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php b/core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php index a33496afb7bf..c7d7dec0efc0 100644 --- a/core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php +++ b/core/modules/help/tests/src/Functional/HelpTopicsSyntaxTest.php @@ -344,7 +344,7 @@ protected function renderHelpTopic(string $content, string $manner) { '#type' => 'inline_template', '#template' => $content . "\n{# " . rand() . " #}", ]; - return (string) \Drupal::service('renderer')->renderPlain($build); + return (string) \Drupal::service('renderer')->renderInIsolation($build); } } diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php index 88cb0fcb94f4..568044e21c1e 100644 --- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php +++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php @@ -125,7 +125,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f // If there's only one field, return it as delta 0. if (empty($elements[0]['#default_value']['fids'])) { $file_upload_help['#description'] = $this->getFilteredDescription(); - $elements[0]['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help); + $elements[0]['#description'] = \Drupal::service('renderer')->renderInIsolation($file_upload_help); } } else { diff --git a/core/modules/inline_form_errors/src/FormErrorHandler.php b/core/modules/inline_form_errors/src/FormErrorHandler.php index da286108b98f..2342737b2bb6 100644 --- a/core/modules/inline_form_errors/src/FormErrorHandler.php +++ b/core/modules/inline_form_errors/src/FormErrorHandler.php @@ -116,7 +116,7 @@ protected function displayErrorMessages(array $form, FormStateInterface $form_st '#context' => ['list_style' => 'comma-list'], ], ]; - $message = $this->renderer->renderPlain($render_array); + $message = $this->renderer->renderInIsolation($render_array); $this->messenger->addError($message); } } diff --git a/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php b/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php index 554691d1fc6d..d40f4190c831 100644 --- a/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php +++ b/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php @@ -137,7 +137,7 @@ public function testErrorMessagesInline() { ); $this->renderer->expects($this->once()) - ->method('renderPlain') + ->method('renderInIsolation') ->willReturnCallback(function ($render_array) { $links = []; foreach ($render_array[1]['#items'] as $item) { @@ -192,7 +192,7 @@ public function testErrorMessagesNotInline() { ); $this->renderer->expects($this->never()) - ->method('renderPlain'); + ->method('renderInIsolation'); $this->testForm['#disable_inline_form_errors'] = TRUE; diff --git a/core/modules/media/src/Controller/MediaFilterController.php b/core/modules/media/src/Controller/MediaFilterController.php index 06e11a1848be..efba5a1fc687 100644 --- a/core/modules/media/src/Controller/MediaFilterController.php +++ b/core/modules/media/src/Controller/MediaFilterController.php @@ -108,7 +108,7 @@ public function preview(Request $request, FilterFormatInterface $filter_format) '#text' => $text, '#format' => $filter_format->id(), ]; - $html = $this->renderer->renderPlain($build); + $html = $this->renderer->renderInIsolation($build); // Load the media item so we can embed the label in the response, for use // in an ARIA label. diff --git a/core/modules/media/src/Plugin/Filter/MediaEmbed.php b/core/modules/media/src/Plugin/Filter/MediaEmbed.php index e372aa93f79e..22007a36fcbb 100644 --- a/core/modules/media/src/Plugin/Filter/MediaEmbed.php +++ b/core/modules/media/src/Plugin/Filter/MediaEmbed.php @@ -378,7 +378,7 @@ protected function renderIntoDomNode(array $build, \DOMNode $node, FilterProcess // We need to render the embedded entity: // - without replacing placeholders, so that the placeholders are // only replaced at the last possible moment. Hence we cannot use - // either renderPlain() or renderRoot(), so we must use render(). + // either renderInIsolation() or renderRoot(), so we must use render(). // - without bubbling beyond this filter, because filters must // ensure that the bubbleable metadata for the changes they make // when filtering text makes it onto the FilterProcessResult diff --git a/core/modules/media_library/src/Form/FileUploadForm.php b/core/modules/media_library/src/Form/FileUploadForm.php index 2afbb0ae5716..abea90f0cc0d 100644 --- a/core/modules/media_library/src/Form/FileUploadForm.php +++ b/core/modules/media_library/src/Form/FileUploadForm.php @@ -184,7 +184,7 @@ protected function buildInputElement(array $form, FormStateInterface $form_state // upload help in the same way, so any theming improvements made to file // fields would also be applied to this upload field. // @see \Drupal\file\Plugin\Field\FieldWidget\FileWidget::formElement() - $form['container']['upload']['#description'] = $this->renderer->renderPlain($file_upload_help); + $form['container']['upload']['#description'] = $this->renderer->renderInIsolation($file_upload_help); return $form; } diff --git a/core/modules/node/src/Controller/NodeController.php b/core/modules/node/src/Controller/NodeController.php index d0ad4be3dfc7..87c9586daee0 100644 --- a/core/modules/node/src/Controller/NodeController.php +++ b/core/modules/node/src/Controller/NodeController.php @@ -193,7 +193,7 @@ public function revisionOverview(NodeInterface $node) { '#template' => '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}', '#context' => [ 'date' => $link, - 'username' => $this->renderer->renderPlain($username), + 'username' => $this->renderer->renderInIsolation($username), 'message' => ['#markup' => $revision->revision_log->value, '#allowed_tags' => Xss::getHtmlTagList()], ], ], diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index a58487c1da0b..88be72514009 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -368,7 +368,7 @@ protected function prepareResults(StatementInterface $found) { $build['#pre_render'][] = [$this, 'removeSubmittedInfo']; // Fetch comments for snippet. - $rendered = $this->renderer->renderPlain($build); + $rendered = $this->renderer->renderInIsolation($build); $this->addCacheableDependency(CacheableMetadata::createFromRenderArray($build)); $rendered .= ' ' . $this->moduleHandler->invoke('comment', 'node_update_index', [$node]); @@ -400,7 +400,7 @@ protected function prepareResults(StatementInterface $found) { if ($type->displaySubmitted()) { $result += [ - 'user' => $this->renderer->renderPlain($username), + 'user' => $this->renderer->renderInIsolation($username), 'date' => $node->getChangedTime(), ]; } @@ -522,7 +522,7 @@ protected function indexNode(NodeInterface $node) { '#suffix' => '</h1>', '#weight' => -1000, ]; - $text = $this->renderer->renderPlain($build); + $text = $this->renderer->renderInIsolation($build); // Fetch extra data normally not visible. $extra = $this->moduleHandler->invokeAll('node_update_index', [$node]); diff --git a/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php b/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php index 72dddd4be493..f6972c2d9915 100644 --- a/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php +++ b/core/modules/node/tests/src/Functional/NodeRevisionsUiTest.php @@ -105,7 +105,7 @@ public function testNodeRevisionDoubleEscapeFix() { '#theme' => 'username', '#account' => $this->editor, ]; - $editor = \Drupal::service('renderer')->renderPlain($username); + $editor = \Drupal::service('renderer')->renderInIsolation($username); // Get original node. $nodes[] = clone $node; diff --git a/core/modules/node/tests/src/Functional/NodeRssCacheTest.php b/core/modules/node/tests/src/Functional/NodeRssCacheTest.php index b56cb362d37f..d25a98bcfa67 100644 --- a/core/modules/node/tests/src/Functional/NodeRssCacheTest.php +++ b/core/modules/node/tests/src/Functional/NodeRssCacheTest.php @@ -80,7 +80,7 @@ public function testNodeRssCacheContent() { // Render the teaser normally. $viewBuilder = $this->container->get('entity_type.manager')->getViewBuilder('node'); $build = $viewBuilder->view($node, 'teaser'); - $output = $this->container->get('renderer')->renderPlain($build); + $output = $this->container->get('renderer')->renderInIsolation($build); // Teaser must contain an "<article" tag from the stable9 theme. $this->assertStringContainsString('<article', (string) $output); diff --git a/core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php b/core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php index b95338fb50d3..32e8d22f6e7c 100644 --- a/core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php +++ b/core/modules/node/tests/src/Kernel/NodeViewBuilderTest.php @@ -90,11 +90,11 @@ public function testPendingRevisionLinks() { $pending_revision->save(); $build = $this->viewBuilder->view($node, 'teaser'); - $output = (string) $this->renderer->renderPlain($build); + $output = (string) $this->renderer->renderInIsolation($build); $this->assertStringContainsString("title=\"$title\"", $output); $build = $this->viewBuilder->view($pending_revision, 'teaser'); - $output = (string) $this->renderer->renderPlain($build); + $output = (string) $this->renderer->renderInIsolation($build); $this->assertStringContainsString("title=\"$draft_title\"", $output); } diff --git a/core/modules/search/tests/src/Kernel/SearchExcerptTest.php b/core/modules/search/tests/src/Kernel/SearchExcerptTest.php index 5fbf7562fd4d..7ad091227f1b 100644 --- a/core/modules/search/tests/src/Kernel/SearchExcerptTest.php +++ b/core/modules/search/tests/src/Kernel/SearchExcerptTest.php @@ -192,7 +192,7 @@ public function testSearchExcerptSimplified() { */ protected function doSearchExcerpt($keys, $render_array, $langcode = NULL) { $render_array = search_excerpt($keys, $render_array, $langcode); - $text = (string) \Drupal::service('renderer')->renderPlain($render_array); + $text = (string) \Drupal::service('renderer')->renderInIsolation($render_array); // The search_excerpt() function adds some extra spaces -- not // important for HTML formatting or this test. Remove these for comparison. return preg_replace('| +|', ' ', $text); diff --git a/core/modules/system/system.install b/core/modules/system/system.install index bdf7d7793729..7474ae9846cf 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -963,7 +963,7 @@ function system_requirements($phase) { ]; } - $entity_update_issues = \Drupal::service('renderer')->renderPlain($build); + $entity_update_issues = \Drupal::service('renderer')->renderInIsolation($build); $requirements['entity_update']['severity'] = REQUIREMENT_ERROR; $requirements['entity_update']['value'] = t('Mismatched entity and/or field definitions'); $requirements['entity_update']['description'] = t('The following changes were detected in the entity type and field definitions. @updates', ['@updates' => $entity_update_issues]); diff --git a/core/modules/system/system.tokens.inc b/core/modules/system/system.tokens.inc index 70041c0d58be..1938f83d2ee8 100644 --- a/core/modules/system/system.tokens.inc +++ b/core/modules/system/system.tokens.inc @@ -134,7 +134,7 @@ function system_tokens($type, $tokens, array $data, array $options, BubbleableMe '#markup' => $slogan, ]; // @todo Fix in https://www.drupal.org/node/2577827 - $replacements[$original] = \Drupal::service('renderer')->renderPlain($build); + $replacements[$original] = \Drupal::service('renderer')->renderInIsolation($build); break; case 'mail': diff --git a/core/modules/system/tests/modules/batch_test/batch_test.callbacks.inc b/core/modules/system/tests/modules/batch_test/batch_test.callbacks.inc index 9f6e741fbb65..1020d1d713ef 100644 --- a/core/modules/system/tests/modules/batch_test/batch_test.callbacks.inc +++ b/core/modules/system/tests/modules/batch_test/batch_test.callbacks.inc @@ -164,7 +164,7 @@ function _batch_test_finished_helper($batch_id, $success, $results, $operations, ], ]; - \Drupal::messenger()->addStatus(\Drupal::service('renderer')->renderPlain($error_message)); + \Drupal::messenger()->addStatus(\Drupal::service('renderer')->renderInIsolation($error_message)); \Drupal::messenger()->addMessage('elapsed time: ' . $elapsed); } diff --git a/core/modules/system/tests/modules/mail_html_test/mail_html_test.module b/core/modules/system/tests/modules/mail_html_test/mail_html_test.module index 0803fb8ad313..d136aff6474e 100644 --- a/core/modules/system/tests/modules/mail_html_test/mail_html_test.module +++ b/core/modules/system/tests/modules/mail_html_test/mail_html_test.module @@ -11,7 +11,7 @@ function mail_html_test_mail($key, &$message, $params) { switch ($key) { case 'render_from_message_param': - $message['body'][] = \Drupal::service('renderer')->renderPlain($params['message']); + $message['body'][] = \Drupal::service('renderer')->renderInIsolation($params['message']); break; } } 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 2983b06797b1..7864c0d003da 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 @@ -70,7 +70,7 @@ public function onRequest(RequestEvent $event) { '#url' => Url::fromRoute('user.page'), '#attributes' => ['title' => 'Themed output generated in a KernelEvents::REQUEST listener'], ]; - $GLOBALS['theme_test_output'] = $this->renderer->renderPlain($more_link); + $GLOBALS['theme_test_output'] = $this->renderer->renderInIsolation($more_link); } } diff --git a/core/modules/system/tests/src/Functional/Form/ElementsLabelsTest.php b/core/modules/system/tests/src/Functional/Form/ElementsLabelsTest.php index f93bbd54b0c3..663e69b67a44 100644 --- a/core/modules/system/tests/src/Functional/Form/ElementsLabelsTest.php +++ b/core/modules/system/tests/src/Functional/Form/ElementsLabelsTest.php @@ -146,7 +146,7 @@ public function testFormsInThemeLessEnvironments() { $form = $this->getFormWithLimitedProperties(); $render_service = $this->container->get('renderer'); // This should not throw any notices. - $render_service->renderPlain($form); + $render_service->renderInIsolation($form); } /** diff --git a/core/modules/system/tests/src/Functional/System/SitesDirectoryHardeningTest.php b/core/modules/system/tests/src/Functional/System/SitesDirectoryHardeningTest.php index 26a193eac6fa..9962df6672f3 100644 --- a/core/modules/system/tests/src/Functional/System/SitesDirectoryHardeningTest.php +++ b/core/modules/system/tests/src/Functional/System/SitesDirectoryHardeningTest.php @@ -60,7 +60,7 @@ public function testSitesDirectoryHardeningConfig() { $requirements = $this->checkSystemRequirements(); $this->assertEquals(REQUIREMENT_WARNING, $requirements['configuration_files']['severity'], 'Warning severity is properly set.'); $this->assertEquals('Protection disabled', (string) $requirements['configuration_files']['value']); - $description = strip_tags((string) \Drupal::service('renderer')->renderPlain($requirements['configuration_files']['description'])); + $description = strip_tags((string) \Drupal::service('renderer')->renderInIsolation($requirements['configuration_files']['description'])); $this->assertStringContainsString('settings.php is not protected from modifications and poses a security risk.', $description); $this->assertStringContainsString('services.yml is not protected from modifications and poses a security risk.', $description); diff --git a/core/modules/system/tests/src/Functional/Theme/TwigTransTest.php b/core/modules/system/tests/src/Functional/Theme/TwigTransTest.php index b4c49301c713..18dd85822c78 100644 --- a/core/modules/system/tests/src/Functional/Theme/TwigTransTest.php +++ b/core/modules/system/tests/src/Functional/Theme/TwigTransTest.php @@ -114,7 +114,7 @@ public function testEmptyTwigTransTags() { $renderer = \Drupal::service('renderer'); try { - $renderer->renderPlain($elements); + $renderer->renderInIsolation($elements); $this->fail('{% trans %}{% endtrans %} did not throw an exception.'); } diff --git a/core/modules/taxonomy/taxonomy.tokens.inc b/core/modules/taxonomy/taxonomy.tokens.inc index f80c83abb13c..9ed3a8dcd813 100644 --- a/core/modules/taxonomy/taxonomy.tokens.inc +++ b/core/modules/taxonomy/taxonomy.tokens.inc @@ -198,7 +198,7 @@ function taxonomy_tokens($type, $tokens, array $data, array $options, Bubbleable case 'description': $build = ['#markup' => $vocabulary->getDescription()]; // @todo Fix in https://www.drupal.org/node/2577827 - $replacements[$original] = \Drupal::service('renderer')->renderPlain($build); + $replacements[$original] = \Drupal::service('renderer')->renderInIsolation($build); break; case 'term-count': diff --git a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php index b0b4d4f5dc14..b23fe6509d8f 100644 --- a/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php +++ b/core/modules/taxonomy/tests/src/Kernel/TermKernelTest.php @@ -167,7 +167,7 @@ public function testTermPreview() { $this->assertNotEmpty($render_array, 'Term view builder is built.'); // Confirm we can render said view. - $rendered = (string) \Drupal::service('renderer')->renderPlain($render_array); + $rendered = (string) \Drupal::service('renderer')->renderInIsolation($render_array); $this->assertNotEmpty(trim($rendered), 'Term is able to be rendered.'); } diff --git a/core/modules/text/src/TextProcessed.php b/core/modules/text/src/TextProcessed.php index a0455d74bdb0..941317534a41 100644 --- a/core/modules/text/src/TextProcessed.php +++ b/core/modules/text/src/TextProcessed.php @@ -59,7 +59,7 @@ public function getValue() { '#langcode' => $item->getLangcode(), ]; // Capture the cacheability metadata associated with the processed text. - $processed_text = $this->getRenderer()->renderPlain($build); + $processed_text = $this->getRenderer()->renderInIsolation($build); $this->processed = FilterProcessResult::createFromRenderArray($build)->setProcessedText((string) $processed_text); } return FilteredMarkup::create($this->processed->getProcessedText()); diff --git a/core/modules/tour/src/TourViewBuilder.php b/core/modules/tour/src/TourViewBuilder.php index d13a20292b0f..b41f846be6a7 100644 --- a/core/modules/tour/src/TourViewBuilder.php +++ b/core/modules/tour/src/TourViewBuilder.php @@ -43,7 +43,7 @@ public function viewMultiple(array $entities = [], $view_mode = 'full', $langcod $location = $tip->getLocation(); $body_render_array = $tip->getBody(); - $body = (string) \Drupal::service('renderer')->renderPlain($body_render_array); + $body = (string) \Drupal::service('renderer')->renderInIsolation($body_render_array); $output = [ 'body' => $body, 'title' => $tip->getLabel(), diff --git a/core/modules/tour/tests/tour_test/src/Plugin/tour/tip/TipPluginImageLegacy.php b/core/modules/tour/tests/tour_test/src/Plugin/tour/tip/TipPluginImageLegacy.php index 580063eb6a2e..d1582fba46a1 100644 --- a/core/modules/tour/tests/tour_test/src/Plugin/tour/tip/TipPluginImageLegacy.php +++ b/core/modules/tour/tests/tour_test/src/Plugin/tour/tip/TipPluginImageLegacy.php @@ -77,7 +77,7 @@ public function getConfigurationOrNot() { return [ 'title' => Html::escape($this->get('label')), - 'body' => $this->token->replace(\Drupal::service('renderer')->renderPlain($image)), + 'body' => $this->token->replace(\Drupal::service('renderer')->renderInIsolation($image)), ]; } diff --git a/core/modules/update/src/Controller/UpdateController.php b/core/modules/update/src/Controller/UpdateController.php index 1f3226d1fc9b..dbd549f65286 100644 --- a/core/modules/update/src/Controller/UpdateController.php +++ b/core/modules/update/src/Controller/UpdateController.php @@ -69,7 +69,7 @@ public function updateStatus() { } if ($fetch_failed) { $message = ['#theme' => 'update_fetch_error_message']; - $this->messenger()->addError($this->renderer->renderPlain($message)); + $this->messenger()->addError($this->renderer->renderInIsolation($message)); } } return $build; diff --git a/core/modules/update/src/Form/UpdateManagerUpdate.php b/core/modules/update/src/Form/UpdateManagerUpdate.php index 9c09009f9623..ee3a6e16525b 100644 --- a/core/modules/update/src/Form/UpdateManagerUpdate.php +++ b/core/modules/update/src/Form/UpdateManagerUpdate.php @@ -251,7 +251,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { if ($fetch_failed) { $message = ['#theme' => 'update_fetch_error_message']; - $this->messenger()->addError(\Drupal::service('renderer')->renderPlain($message)); + $this->messenger()->addError(\Drupal::service('renderer')->renderInIsolation($message)); } if (empty($projects)) { diff --git a/core/modules/update/update.module b/core/modules/update/update.module index 4d3337beaabf..194ec642aec2 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -95,7 +95,7 @@ function update_page_top() { // them before using // \Drupal\Core\Messenger\MessengerInterface::addStatus(). if (isset($status[$type]['description']) && is_array($status[$type]['description'])) { - $status[$type]['description'] = \Drupal::service('renderer')->renderPlain($status[$type]['description']); + $status[$type]['description'] = \Drupal::service('renderer')->renderInIsolation($status[$type]['description']); } if (!empty($verbose)) { if (isset($status[$type]['severity'])) { diff --git a/core/modules/user/tests/src/Functional/Views/AccessRoleTest.php b/core/modules/user/tests/src/Functional/Views/AccessRoleTest.php index 088affc6f433..6aaf342bedce 100644 --- a/core/modules/user/tests/src/Functional/Views/AccessRoleTest.php +++ b/core/modules/user/tests/src/Functional/Views/AccessRoleTest.php @@ -132,7 +132,7 @@ public function testRenderCaching() { // First access as user with access. $build = DisplayPluginBase::buildBasicRenderable('test_access_role', 'default'); $account_switcher->switchTo($this->normalUser); - $result = $renderer->renderPlain($build); + $result = $renderer->renderInIsolation($build); $this->assertContains('user.roles', $build['#cache']['contexts']); $this->assertEquals(['config:views.view.test_access_role'], $build['#cache']['tags']); $this->assertEquals(Cache::PERMANENT, $build['#cache']['max-age']); @@ -141,7 +141,7 @@ public function testRenderCaching() { // Then without access. $build = DisplayPluginBase::buildBasicRenderable('test_access_role', 'default'); $account_switcher->switchTo($this->webUser); - $result = $renderer->renderPlain($build); + $result = $renderer->renderInIsolation($build); // @todo Fix this in https://www.drupal.org/node/2551037, // DisplayPluginBase::applyDisplayCacheabilityMetadata() is not invoked when // using buildBasicRenderable() and a Views access plugin returns FALSE. diff --git a/core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php b/core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php index fc12d23e8a4e..467a34f6e3a9 100644 --- a/core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php +++ b/core/modules/user/tests/src/Kernel/Views/AccessPermissionTest.php @@ -98,12 +98,12 @@ public function testRenderCaching() { // First access as user without access. $build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default'); $account_switcher->switchTo($this->webUser); - $this->assertEmpty($renderer->renderPlain($build)); + $this->assertEmpty($renderer->renderInIsolation($build)); // Then with access. $build = DisplayPluginBase::buildBasicRenderable('test_access_perm', 'default'); $account_switcher->switchTo($this->normalUser); - $this->assertNotEmpty($renderer->renderPlain($build)); + $this->assertNotEmpty($renderer->renderInIsolation($build)); } } diff --git a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php b/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php index 3d3444374b6c..80309f5b90f6 100644 --- a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php +++ b/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php @@ -287,7 +287,7 @@ protected function stripAdminAndAnchorTagsFromResults(array $results) { foreach (Element::children($results) as $id) { $entity = $results[$id]['#row']->_entity; $stripped_results[$entity->bundle()][$id] = ViewsRenderPipelineMarkup::create( - Xss::filter($this->renderer->renderPlain($results[$id]), $allowed_tags) + Xss::filter($this->renderer->renderInIsolation($results[$id]), $allowed_tags) ); } diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php index cba59b7a2c34..dc3b2da42796 100644 --- a/core/modules/views/src/Plugin/views/PluginBase.php +++ b/core/modules/views/src/Plugin/views/PluginBase.php @@ -418,10 +418,10 @@ function ($children, $elements) { ]; // Currently you cannot attach assets to tokens with - // Renderer::renderPlain(). This may be unnecessarily limiting. Consider + // Renderer::renderInIsolation(). This may be unnecessarily limiting. Consider // using Renderer::executeInRenderContext() instead. // @todo: https://www.drupal.org/node/2566621 - return (string) $this->getRenderer()->renderPlain($build); + return (string) $this->getRenderer()->renderInIsolation($build); } else { return Xss::filterAdmin($text); diff --git a/core/modules/views/src/Plugin/views/style/StylePluginBase.php b/core/modules/views/src/Plugin/views/style/StylePluginBase.php index d35b14bd5dfd..09044a4bf38c 100644 --- a/core/modules/views/src/Plugin/views/style/StylePluginBase.php +++ b/core/modules/views/src/Plugin/views/style/StylePluginBase.php @@ -699,12 +699,12 @@ protected function renderFields(array $result) { // - HTML views are rendered inside a render context: then we want to // use ::render(), so that attachments and cacheability are bubbled. // - non-HTML views are rendered outside a render context: then we - // want to use ::renderPlain(), so that no bubbling happens + // want to use ::renderInIsolation(), so that no bubbling happens if ($renderer->hasRenderContext()) { $renderer->render($data); } else { - $renderer->renderPlain($data); + $renderer->renderInIsolation($data); } // Extract field output from the render array and post process it. diff --git a/core/modules/views/tests/modules/views_test_data/views_test_data.views_execution.inc b/core/modules/views/tests/modules/views_test_data/views_test_data.views_execution.inc index d877dbc67986..12fccbb428a8 100644 --- a/core/modules/views/tests/modules/views_test_data/views_test_data.views_execution.inc +++ b/core/modules/views/tests/modules/views_test_data/views_test_data.views_execution.inc @@ -24,7 +24,7 @@ function views_test_data_views_form_substitutions() { $render = ['#markup' => '<em>unescaped</em>']; return [ '<!--will-be-escaped-->' => '<em>escaped</em>', - '<!--will-be-not-escaped-->' => \Drupal::service('renderer')->renderPlain($render), + '<!--will-be-not-escaped-->' => \Drupal::service('renderer')->renderInIsolation($render), ]; } diff --git a/core/modules/views/tests/src/Functional/Plugin/CacheTagTest.php b/core/modules/views/tests/src/Functional/Plugin/CacheTagTest.php index 3e5b14fa8628..4199934359f3 100644 --- a/core/modules/views/tests/src/Functional/Plugin/CacheTagTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/CacheTagTest.php @@ -129,7 +129,7 @@ public function testTagCaching() { $renderer = \Drupal::service('renderer'); $view = Views::getView('test_tag_cache'); $build = $view->buildRenderable(); - $renderer->renderPlain($build); + $renderer->renderInIsolation($build); // Saving the view should invalidate the tags. $cache_plugin = $view->display_handler->getPlugin('cache'); @@ -143,7 +143,7 @@ public function testTagCaching() { $view->destroy(); $build = $view->buildRenderable(); - $renderer->renderPlain($build); + $renderer->renderInIsolation($build); // Test invalidating the nodes in this view invalidates the cache. $cache_plugin = $view->display_handler->getPlugin('cache'); @@ -157,7 +157,7 @@ public function testTagCaching() { $view->destroy(); $build = $view->buildRenderable(); - $renderer->renderPlain($build); + $renderer->renderInIsolation($build); // Test saving a node in this view invalidates the cache. $cache_plugin = $view->display_handler->getPlugin('cache'); @@ -172,7 +172,7 @@ public function testTagCaching() { $view->destroy(); $build = $view->buildRenderable(); - $renderer->renderPlain($build); + $renderer->renderInIsolation($build); // Test saving a node not in this view invalidates the cache too. $cache_plugin = $view->display_handler->getPlugin('cache'); @@ -186,7 +186,7 @@ public function testTagCaching() { $view->destroy(); $build = $view->buildRenderable(); - $renderer->renderPlain($build); + $renderer->renderInIsolation($build); // Test that invalidating a tag for a user, does not invalidate the cache, // as the user entity type will not be contained in the views cache tags. @@ -205,7 +205,7 @@ public function testTagCaching() { // caching. \Drupal::service('cache_tags.invalidator')->invalidateTags($view->storage->getCacheTagsToInvalidate()); $build = $view->buildRenderable(); - $renderer->renderPlain($build); + $renderer->renderInIsolation($build); // Test the cacheFlush method invalidates the cache. $cache_plugin = $view->display_handler->getPlugin('cache'); diff --git a/core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php b/core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php index 9ddbc22b4e1e..be26473ab94f 100644 --- a/core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/FieldRenderedEntityTest.php @@ -127,7 +127,7 @@ public function testRenderedEntityWithoutAndWithField() { '#display_id' => 'default', ]; $renderer = \Drupal::service('renderer'); - $renderer->renderPlain($build); + $renderer->renderInIsolation($build); for ($i = 1; $i <= 3; $i++) { $view_field = (string) $view->style_plugin->getField($i - 1, 'rendered_entity'); $search_result = str_contains($view_field, "Test $i"); @@ -150,7 +150,7 @@ public function testRenderedEntityWithoutAndWithField() { '#display_id' => 'default', ]; - $renderer->renderPlain($build); + $renderer->renderInIsolation($build); for ($i = 1; $i <= 3; $i++) { $view_field = (string) $view->style_plugin->getField($i - 1, 'rendered_entity'); $search_result = str_contains($view_field, "Test $i"); diff --git a/core/modules/views/tests/src/Kernel/Handler/SortRandomTest.php b/core/modules/views/tests/src/Kernel/Handler/SortRandomTest.php index 235beb068a0b..3444cfe84882 100644 --- a/core/modules/views/tests/src/Kernel/Handler/SortRandomTest.php +++ b/core/modules/views/tests/src/Kernel/Handler/SortRandomTest.php @@ -122,7 +122,7 @@ public function testRandomOrderingWithRenderCaching() { $render_cache = \Drupal::service('render_cache'); $original = $build = DisplayPluginBase::buildBasicRenderable($view_random->id(), 'default'); - $result = $renderer->renderPlain($build); + $result = $renderer->renderInIsolation($build); $original['#cache'] += ['contexts' => []]; $original['#cache']['contexts'] = Cache::mergeContexts($original['#cache']['contexts'], $this->container->getParameter('renderer.config')['required_cache_contexts']); @@ -130,7 +130,7 @@ public function testRandomOrderingWithRenderCaching() { $this->assertFalse($render_cache->get($original), 'Ensure there is no render cache entry.'); $build = DisplayPluginBase::buildBasicRenderable($view_random->id(), 'default'); - $result2 = $renderer->renderPlain($build); + $result2 = $renderer->renderInIsolation($build); // Ensure that the random ordering works and don't produce the same result. // We use assertNotSame and cast values to strings since HTML tags are diff --git a/core/modules/views/tests/src/Kernel/ModuleTest.php b/core/modules/views/tests/src/Kernel/ModuleTest.php index a9b8969cfad5..e80ea470f353 100644 --- a/core/modules/views/tests/src/Kernel/ModuleTest.php +++ b/core/modules/views/tests/src/Kernel/ModuleTest.php @@ -251,23 +251,23 @@ public function testViewsEmbedView() { $renderer = \Drupal::service('renderer'); $result = views_embed_view('test_argument'); - $renderer->renderPlain($result); + $renderer->renderInIsolation($result); $this->assertCount(5, $result['view_build']['#view']->result); $result = views_embed_view('test_argument', 'default', 1); - $renderer->renderPlain($result); + $renderer->renderInIsolation($result); $this->assertCount(1, $result['view_build']['#view']->result); $result = views_embed_view('test_argument', 'default', '1,2'); - $renderer->renderPlain($result); + $renderer->renderInIsolation($result); $this->assertCount(2, $result['view_build']['#view']->result); $result = views_embed_view('test_argument', 'default', '1,2', 'John'); - $renderer->renderPlain($result); + $renderer->renderInIsolation($result); $this->assertCount(1, $result['view_build']['#view']->result); $result = views_embed_view('test_argument', 'default', '1,2', 'John,George'); - $renderer->renderPlain($result); + $renderer->renderInIsolation($result); $this->assertCount(2, $result['view_build']['#view']->result); } diff --git a/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php b/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php index 91a4f4250246..e0ed5262dc34 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/CacheTest.php @@ -406,7 +406,7 @@ public function testArgumentDefaultCache() { /** @var \Drupal\Core\Render\RendererInterface $renderer */ $renderer = \Drupal::service('renderer'); - $renderer->renderPlain($output); + $renderer->renderInIsolation($output); $this->assertEquals(['config:views.view.test_view', 'example_tag'], $output['#cache']['tags']); } diff --git a/core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php b/core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php index f116747b6ce8..e292806bf27e 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/PagerKernelTest.php @@ -51,7 +51,7 @@ public function testSetPagerMethods() { $output = $view->preview(); - \Drupal::service('renderer')->renderPlain($output); + \Drupal::service('renderer')->renderInIsolation($output); $this->assertSame(CacheBackendInterface::CACHE_PERMANENT, $output['#cache']['max-age']); foreach (['setItemsPerPage', 'setOffset', 'setCurrentPage'] as $method) { @@ -60,7 +60,7 @@ public function testSetPagerMethods() { $view->{$method}(1); $output = $view->preview(); - \Drupal::service('renderer')->renderPlain($output); + \Drupal::service('renderer')->renderInIsolation($output); $this->assertSame(CacheBackendInterface::CACHE_PERMANENT, $output['#cache']['max-age'], 'Max age kept.'); } diff --git a/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php index a5b7b8b5b41e..808702d09627 100644 --- a/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php @@ -548,7 +548,7 @@ public function testRenderAsLinkWithPathAndTokens($path, $tokens, $link_html) { ]; $this->renderer->expects($this->once()) - ->method('renderPlain') + ->method('renderInIsolation') ->with($build) ->willReturn('base:test-path/123'); @@ -612,7 +612,7 @@ public function testRenderAsExternalLinkWithPathAndTokens($path, $tokens, $link_ ]; $this->renderer->expects($this->once()) - ->method('renderPlain') + ->method('renderInIsolation') ->with($build) ->willReturn($context['context_path']); @@ -846,7 +846,7 @@ public function testElementClassesWithTokens() { // being tested correctly handles tokens when generating the element's class // attribute. $this->renderer->expects($this->any()) - ->method('renderPlain') + ->method('renderInIsolation') ->with($build) ->willReturn($expected_result); diff --git a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php index b4deb7e28cd2..3604e856e481 100644 --- a/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php +++ b/core/tests/Drupal/KernelTests/Core/Asset/AttachedAssetsTest.php @@ -95,8 +95,8 @@ public 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 = (string) $this->renderer->renderPlain($css_render_array); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_css = (string) $this->renderer->renderInIsolation($css_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); $query_string = $this->container->get('asset.query_string')->get(); $this->assertStringContainsString('<link rel="stylesheet" media="all" href="' . $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/bar.css') . '?' . $query_string . '" />', $rendered_css, 'Rendering an external CSS file.'); $this->assertStringContainsString('<script src="' . $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/foo.js') . '?' . $query_string . '"></script>', $rendered_js, 'Rendering an external JavaScript file.'); @@ -135,8 +135,8 @@ public 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 = (string) $this->renderer->renderPlain($css_render_array); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_css = (string) $this->renderer->renderInIsolation($css_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); $this->assertStringContainsString('<link rel="stylesheet" media="all" href="http://example.com/stylesheet.css" />', $rendered_css, 'Rendering an external CSS file.'); $this->assertStringContainsString('<script src="http://example.com/script.js"></script>', $rendered_js, 'Rendering an external JavaScript file.'); } @@ -150,7 +150,7 @@ public function testAttributes() { $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); $expected_1 = '<script src="http://example.com/deferred-external.js" foo="bar" defer></script>'; $expected_2 = '<script src="' . $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/deferred-internal.js') . '?v=1" defer bar="foo"></script>'; $this->assertStringContainsString($expected_1, $rendered_js, 'Rendered external JavaScript with correct defer and random attributes.'); @@ -166,7 +166,7 @@ public function testAggregatedAttributes() { $js = $this->assetResolver->getJsAssets($assets, TRUE, \Drupal::languageManager()->getCurrentLanguage())[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); $expected_1 = '<script src="http://example.com/deferred-external.js" foo="bar" defer></script>'; $expected_2 = '<script src="' . $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/deferred-internal.js') . '?v=1" defer bar="foo"></script>'; $this->assertStringContainsString($expected_1, $rendered_js, 'Rendered external JavaScript with correct defer and random attributes.'); @@ -204,7 +204,7 @@ public function testSettings() { $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); // Cast to string since this returns a \Drupal\Core\Render\Markup object. - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); // Parse the generated drupalSettings <script> back to a PHP representation. $startToken = '{'; @@ -240,7 +240,7 @@ public function testHeaderHTML() { $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[0]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); $query_string = $this->container->get('asset.query_string')->get(); $this->assertStringContainsString('<script src="' . $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/header.js') . '?' . $query_string . '"></script>', $rendered_js, 'The JS asset in common_test/js-header appears in the header.'); $this->assertStringContainsString('<script src="' . $this->fileUrlGenerator->generateString('core/misc/drupal.js'), $rendered_js, 'The JS asset of the direct dependency (core/drupal) of common_test/js-header appears in the header.'); @@ -268,7 +268,7 @@ public function testVersionQueryString() { $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); $this->assertStringContainsString('core/assets/vendor/once/once.min.js?v=1.0.1', $rendered_js, 'JavaScript version identifiers correctly appended to URLs'); } @@ -297,7 +297,7 @@ public function testRenderOrder() { // Retrieve the rendered JavaScript and test against the regex. $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); $matches = []; if (preg_match_all('/weight_([-0-9]+_[0-9]+)/', $rendered_js, $matches)) { $result = $matches[1]; @@ -339,7 +339,7 @@ public function testRenderOrder() { // Retrieve the rendered CSS and test against the regex. $css = $this->assetResolver->getCssAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage()); $css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css); - $rendered_css = (string) $this->renderer->renderPlain($css_render_array); + $rendered_css = (string) $this->renderer->renderInIsolation($css_render_array); $matches = []; if (preg_match_all('/([a-z]+)_weight_([-0-9]+_[0-9]+)/', $rendered_css, $matches)) { $result = $matches[0]; @@ -362,7 +362,7 @@ public function testRenderDifferentWeight() { $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); // Verify that lighter CSS assets are rendered first. $this->assertLessThan(strpos($rendered_js, 'first.js'), strpos($rendered_js, 'lighter.css')); // Verify that lighter JavaScript assets are rendered first. @@ -387,7 +387,7 @@ public function testAlter() { // takes place. $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); // Verify that JavaScript weight is correctly altered by the alter hook. $this->assertLessThan(strpos($rendered_js, 'core/misc/tableselect.js'), strpos($rendered_js, 'alter.js')); } @@ -409,7 +409,7 @@ public function testLibraryAlter() { $assets = AttachedAssets::createFromRenderArray($build); $js = $this->assetResolver->getJsAssets($assets, FALSE, \Drupal::languageManager()->getCurrentLanguage())[1]; $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); $this->assertStringContainsString('core/assets/vendor/jquery-form/jquery.form.min.js', (string) $rendered_js, 'Altered library dependencies are added to the page.'); } @@ -458,9 +458,9 @@ public function testAddJsFileWithQueryString() { $this->assertArrayHasKey('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2', $js); $css_render_array = \Drupal::service('asset.css.collection_renderer')->render($css); - $rendered_css = (string) $this->renderer->renderPlain($css_render_array); + $rendered_css = (string) $this->renderer->renderInIsolation($css_render_array); $js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js); - $rendered_js = (string) $this->renderer->renderPlain($js_render_array); + $rendered_js = (string) $this->renderer->renderInIsolation($js_render_array); $query_string = $this->container->get('asset.query_string')->get(); $this->assertStringContainsString('<link rel="stylesheet" media="all" href="' . str_replace('&', '&', $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/querystring.css?arg1=value1&arg2=value2')) . '&' . $query_string . '" />', $rendered_css, 'CSS file with query string gets version query string correctly appended..'); $this->assertStringContainsString('<script src="' . str_replace('&', '&', $this->fileUrlGenerator->generateString('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2')) . '&' . $query_string . '"></script>', $rendered_js, 'JavaScript file with query string gets version query string correctly appended.'); diff --git a/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php b/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php index db369a238cdc..eec9e4403f30 100644 --- a/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Render/RenderTest.php @@ -72,4 +72,15 @@ public function testProcessAttached() { $renderer->renderBarePage($build, '', 'maintenance_page'); } + /** + * Tests the deprecation of \Drupal\Core\Render\Renderer::renderPlain() + * + * @group legacy + */ + public function testDeprecateRenderPlain() { + $message = ['#markup' => 'Test']; + \Drupal::service('renderer')->renderPlain($message); + $this->expectDeprecation('Renderer::renderPlain() is deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Instead, you should use ::renderInIsolation(). See https://www.drupal.org/node/3407994'); + } + } diff --git a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php index d6efc9b3888f..ba74ff893f37 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php @@ -93,14 +93,14 @@ public function testRenderRecursionWithNestedRender() { } /** - * ::renderPlain() may be called from anywhere. + * ::renderInIsolation() may be called from anywhere. * * Including from inside of another ::renderRoot() call. * * @covers ::renderRoot - * @covers ::renderPlain + * @covers ::renderInIsolation */ - public function testRenderRecursionWithNestedRenderPlain() { + public function testRenderRecursionWithNestedRenderInIsolation() { [$complex_child_markup, $parent_markup, $complex_child_template] = $this->setUpRenderRecursionComplexElements(); $renderer = $this->renderer; $this->setUpRequest(); @@ -108,7 +108,7 @@ public function testRenderRecursionWithNestedRenderPlain() { $complex_child = $complex_child_template; $callable = function ($elements) use ($renderer, $complex_child) { - $elements['#markup'] = $renderer->renderPlain($complex_child); + $elements['#markup'] = $renderer->renderInIsolation($complex_child); $this->assertEquals('<p>This is a rendered placeholder!</p>', $elements['#markup'], 'Rendered complex child output as expected, with the placeholder replaced.'); return $elements; }; diff --git a/core/tests/Drupal/Tests/Core/Render/RendererTest.php b/core/tests/Drupal/Tests/Core/Render/RendererTest.php index de0897251cfa..9f613530203e 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererTest.php @@ -634,7 +634,7 @@ public function testRenderAccessCacheabilityDependencyInheritance() { '#access' => AccessResult::allowed()->addCacheContexts(['user']), ]; - $this->renderer->renderPlain($build); + $this->renderer->renderInIsolation($build); $this->assertEqualsCanonicalizing(['languages:language_interface', 'theme', 'user'], $build['#cache']['contexts']); } -- GitLab