diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index a99f19c7bf5fcdf0b6f7b69652f5594390a523b3..9857c66ff2dd65f6b9e3c3bf41f20821a8a08b65 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 60d8272c8b9a717d67c7bf51a3d2e42d0622e609..9c8a859768a20ab9fc72c3e3d83e7d3cf61837da 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 7a9dd005f60db195f5d493632e0967eb54c33800..a498d2dccef3beff6ddf90a4ecaab32b4d3e9c67 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 c6fa8d2ba807d234450aed78ee4a0c11767cf5bd..581133a87be86ecd557a5183c3039006225176ac 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 0a5ffc02ab6b6f47839abb3ef2c29d645bcf1202..46cf9e2084c21d9400152c833d2c3ad8904badd6 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 262b3db0df47c0e79f2f84a8e302ac752cd9ac76..2b9b7cd5926dcce8fb34c6ac6008d5f83307f98b 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 a768b0b8978cb33d0836bc17f8cbd4aecde99bd6..9cb8e0a848fb0644c8d03a2f5db952b5d5742055 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 9ad0d34d7894d5b76fe7f71016d1e21845dfb7a5..3ce49244de1f50c872172858f8f4d62f589120f9 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 1344c5631b9ba756a70e0893088504c83db6a337..310e4fcc836a9621001461601b602713e474f72e 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 997a984df16c45d04be4da598d9458e7f0f8f95d..6a5dbd0f4a5f532dd0ef6ae641bc58ca16441e76 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 2f86bb89758ab848b5dc0b79c5ff9163e3b2d3d3..0928695ed156de4b00bb5705823440f381221152 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 891ae25631445d297bc9ab1051bab7c10ece8f10..fd26bbc58e4c57cc137c6f34bdb97e7eb5fdd374 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 492eb6ffc9cc29ea72d6ef1cabb4bc4f927a7201..a7c3c2c9f622c9f8208cd6f67b67aed64cd17de8 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 af39f3cea2ae6dc6f7d8b649b82b8b00edb8025f..c98c23e1bb397c7c251b20b2512f74ecbd819139 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 da17189c6daa51d96db70d7718c1dbcab3c4dc24..55be906a69de2e0fae9b306582cdc283a6057881 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 271a01342e15113e5f57d7cf0aec08aa4668c66b..e1d8b6196a52360b514c12fefd352d44b4d260e2 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 534d0718f125a5e8c59a2075422ff9a107dd4709..f68daf91e3e31346f6a2b9565dae13e0c1c561f1 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 14d568f4fed9d0d1de43f63fd4b12257ad870c9b..c6972a420aa391e1b52b621befdd6460433f3775 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 b97f178a8a4253d1b49909bac171ce08e78e05ce..525c8b15d5c47c3b60d73e71aca3057084ef40be 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 a27740b6b86ee0833d4dc72f3e267a26d0048c5c..b15987543ce9ec684d2576167deb2d5c92615e47 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 2edfae34c3339686c1979f261442b79fd9bf9128..62db3ddf1a43e96008fe042c4cf02e23aa09d57d 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 c6cae99e5a8b90a27f32d56bf2e49076d33d1cb4..061933dc96aa56025b39d1773d482fed7a2be632 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 b6fa665156d4674bf40991629f69332083aac8b1..6ac1986835dcf0088f206e5f4ddaad98d572fe55 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 e2395f56fb67fd37eaa962e17299e9774eee84f8..e918621b711560535f579186f5626050805d0308 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 a33496afb7bf566dc920bec48ba9824fc059ecd8..c7d7dec0efc0b4bec9d2ef4b43ee959de3be259a 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 88cb0fcb94f49d60da68295d753b43e4fcecbbca..568044e21c1e5e90d831557275a4619a6167cd1f 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 da286108b98f5f2d248fb6dda139751f3e7c0b86..2342737b2bb61c3e8c385388b23f6a1a717063d0 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 554691d1fc6d6048f486188ba6912ab024d02a26..d40f4190c831bbbb527f453283688fd0e569495b 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 06e11a1848bed83b1695be5ab02896f409762592..efba5a1fc6871964dad0ef045cca1f48a38d1324 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 e372aa93f79efbf51b845b825db7a0076099b6a7..22007a36fcbbb117a897076d476736c756c06f86 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 2afbb0ae5716dbf55c478dcb87b78ea3ed6f19c7..abea90f0cc0d293ffbee8a79f0a8b406e340b51d 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 d0ad4be3dfc7988e3145cd951912b4c6f29afd94..87c9586daee00c3a86be09b2b4a07185b1751577 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 a58487c1da0b6c1ddf6be95c377965ef75971fae..88be72514009e3a7d9d44a04d5c93a8ae0614427 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 72dddd4be493cf823493c5460cb3f9380f669bb9..f6972c2d9915f5b2cdba5873a894ec70781ce8fd 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 b56cb362d37f0a979b03fce366b72ee86b5352f7..d25a98bcfa67e57532c9cd4a4c7b88b60f9d1b5f 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 b95338fb50d390e18fd4830bc55cb575ed1be921..32e8d22f6e7c127cd05df934f768823466a3e2ac 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 5fbf7562fd4d319a52221b0ce3aeb75927117ed5..7ad091227f1b5b7ec7e5d3bc70a245ff896afa9e 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 bdf7d7793729e4b2c962e75af85dbfd456018a24..7474ae9846cf5dd3a4d720fb2a4bc270ad6003a1 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 70041c0d58be5b32dcdc713d4e31d8b5d12d985a..1938f83d2ee8865d0c1e1b3b7c843def4953f69a 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 9f6e741fbb65338b38ef87cac47e33f4f32a43b6..1020d1d713ef8ffc54b4cd49652ac6c432fd3bdc 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 0803fb8ad313a98ed0342533cf32759cc2ea5cfc..d136aff6474e742b6e82bde0d804167b4f696e8c 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 2983b06797b178742f01dfd266541a6d39a5b66d..7864c0d003dab00949b6bfbf1d0da0952a756b1c 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 f93bbd54b0c3da6b2d7ae6f538fcf7c713dab06a..663e69b67a44469812c42df5bef84ddc99be990f 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 26a193eac6fadf00c88589d6aed0fe64b0bc4a8d..9962df6672f3d0b5789bd3c8853a6a09c2a8b55f 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 b4c49301c7137a8ef2700fcdf30d6d6c410cf297..18dd85822c78f6200a95aae00e9eada30c7b8764 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 f80c83abb13ce4d72bba94ab90f70bf323e92f55..9ed3a8dcd813bbdb8e3371e40f1ece170b5cb5b1 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 b0b4d4f5dc140c4b47d390d85c55e3e7bd2f0c64..b23fe6509d8ffd3acfbe9ca8730aa37e0c7fd26e 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 a0455d74bdb0a4352dd9caea11fb52f623359971..941317534a41cf5d551460b98756aafc58b6e798 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 d13a20292b0f7362154ca72c4453b2e06cb86941..b41f846be6a721b371e1d9d55ea9c34da6cf20a4 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 580063eb6a2e175857ff969828eb811468414cc1..d1582fba46a1aab9bd2e4279238410c1ac7b351b 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 1f3226d1fc9b5dc2437a1c825cffd37fee86ff69..dbd549f65286d4288804f25e89988e492f88f180 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 9c09009f96233449b1ad29117f72a8ea1ed5ad67..ee3a6e16525bfe28d6b25a02ae29a695db2d814d 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 4d3337beaabfc63567431270afdf859fc05fdab2..194ec642aec2eaa0c5ea393ec46c9f74685448b7 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 088affc6f43385f1fad651c13aab69d1f74c91ad..6aaf342bedce5063e70e6d643ec4cccbfec712c4 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 fc12d23e8a4e770eb1e72c2200ea04a0e28ea992..467a34f6e3a9665d6641846334eae9fb6aaedbc7 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 3d3444374b6c922b4c6847677de7f141de394d50..80309f5b90f64781b90d6daeab4282d2a094aa66 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 cba59b7a2c34c823a0bf3670198730381fe75e59..dc3b2da427969dbe397ec66241436901fa32e87e 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 d35b14bd5dfd47a79d58109ee2d39959617f5b7a..09044a4bf38ccf5dcc1a35fae419face919a2740 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 d877dbc67986178d617a5dde77c891339eb24239..12fccbb428a8adb6b982d21ee9f5b8058f31b698 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 3e5b14fa8628bd708ed182f1315dac8d1f6aa661..4199934359f39d3711a6dd771d032fc48b68b770 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 9ddbc22b4e1ea54723c4fe0446096b0d9cc6c236..be26473ab94ff73153daffc557062d1bb470ee0a 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 235beb068a0b837fe39f481f044206fd1a83b1aa..3444cfe8488208a0419e0cc629b5ef1bf5a27dfd 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 a9b8969cfad5c67c554f2cf457c820dcf7129b88..e80ea470f3531c61975d2cc35ab2933f39e261b3 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 91a4f425024698d6642ff54d05b78e83483e42c4..e0ed5262dc34c443c599b31140f4be1186e3ef55 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 f116747b6ce8e36525f7dab32e25cb1c36c62771..e292806bf27e607666e4ab937eee7e2ec21ffcba 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 a5b7b8b5b41eef8656035fe6d50f2f195f746498..808702d0962773ee047e93be48a88fc3a8d1f513 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 b4deb7e28cd273de5324835775e6f81b616fcf9b..3604e856e481c92d1ce25ab2d622468755aad5ea 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 db369a238cdc66b6c8c82003a1032e713312ca3c..eec9e4403f3053354864b99e57da03593e03afb5 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 d6efc9b3888f89886a70b30d2836c2cd1c83ef78..ba74ff893f374edf669ca0807c39cdb1a16253c3 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 de0897251cfa9f47511101f63030f6cc4b12268e..9f613530203e9e5eb9a3b6a80c3b5da21855a751 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']); }