Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-fro/1c9b5fcf778edcc49eb39dab292cbc0c to your computer and use it in GitHub Desktop.
Save a-fro/1c9b5fcf778edcc49eb39dab292cbc0c to your computer and use it in GitHub Desktop.
diff --git a/src/Controller/ParagraphsPreviewController.php b/src/Controller/ParagraphsPreviewController.php
index 3fe50c4..924c75f 100644
--- a/src/Controller/ParagraphsPreviewController.php
+++ b/src/Controller/ParagraphsPreviewController.php
@@ -176,6 +176,13 @@ class ParagraphsPreviewController extends ControllerBase {
// EntityViewBuilder::viewFieldItem().
$elements = $parent_clone->{$parent_field_name}->view($parent_view_mode);
+ // When layout builder is enabled for an entity, viewBuilder->view_field()
+ // returns and empty array. Using default display options instead returns
+ // the render array we were expecting so we can preview it.
+ if (empty($elements)) {
+ $elements = $parent_clone->{$parent_field_name}->view();
+ }
+
// Extract the part of the render array we need.
$output = isset($elements[0]) ? $elements[0] : [];
if (isset($elements['#access'])) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment