- Issue created by @kaszarobert
- Status changed to Needs review
8 months ago 1:25pm 9 April 2024 - last update
8 months ago 7 pass - Status changed to RTBC
7 months ago 6:09pm 10 May 2024
We're experiencing that when rendering an entity via code and passing it to twig, it renders in an altered layout defined in Layout Library.
if (!empty($productId)) {
$entityType = 'commerce_product';
$viewMode = 'modal';
$storage = \Drupal::entityTypeManager()->getStorage($entityType);
$productEntity = $storage->load($productId);
if ($productEntity->access('view', \Drupal::currentUser())) {
$viewBuilder = \Drupal::entityTypeManager()->getViewBuilder($entityType);
$build = $viewBuilder->view($productEntity, $viewMode);
return [
'id' => $productVariationId,
'rendered' => \Drupal::service('renderer')->renderRoot($build),
];
}
}
In our use case we need the altered only for the Default view mode.
1.0
Code