diff --git a/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php b/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php index 9627c99876..c604d650ae 100644 --- a/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php +++ b/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php @@ -12,6 +12,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\help\Plugin\HelpSection\HelpSectionPluginBase; use Drupal\Core\Render\RendererInterface; +use Drupal\Core\Render\RenderContext; use Drupal\Core\StringTranslation\TranslationManager; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -233,13 +234,19 @@ public function renderTopicForSearch($topic_id, LanguageInterface $language) { $topic['title'] = $this->renderer->renderPlain($title_build); $cacheable_metadata = CacheableMetadata::createFromRenderArray($title_build); - // Render the body in this language. + // Render the body in this language. For this, we need to set up a render + // context, because the Twig plugins that provide the body assumes one + // is present. + $context = new RenderContext(); $build = [ - 'body' => $plugin->getBody(), + 'body' => $this->renderer->executeInRenderContext($context, [$plugin, 'getBody']), ]; $topic['text'] = $this->renderer->renderPlain($build); $cacheable_metadata->addCacheableDependency(CacheableMetadata::createFromRenderArray($build)); $cacheable_metadata->addCacheableDependency($plugin); + if (!$context->isEmpty()) { + $cacheable_metadata->addCacheableDependency($context->pop()); + } // Add the other information. $topic['url'] = $plugin->toUrl();