Translate embedded blocks and views when rendering node programmatically

Created on 16 December 2022, about 2 years ago
Updated 28 July 2024, 5 months ago

Problem/Motivation

I'm rendering a node programmatically using this code:

$view_builder = \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId());
$language = $entity->language()->getId();
$build = $view_builder->view($entity, 'full', $language);
$body = \Drupal::service('renderer')->renderPlain($build)

When the node has views or blocks embedded in it, the translations are not picked up and the text in my $body is always the one coming from the default language.
When viewing the node everything is fine, but i'd expect the same thing to happen when i render the node programmatically...

Steps to reproduce

Put my code for example in a hook node save and set a node type to be displayed with layout builder putting a translated block in it.

💬 Support request
Status

Closed: outdated

Version

11.0 🔥

Component
Layout builder 

Last updated 4 days ago

Created by

🇫🇮Finland joey-santiago

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024