Preview not working when using layout builder on full content view mode on content type

Created on 8 June 2020, over 4 years ago
Updated 3 February 2023, almost 2 years ago

When I use the layout builder on a content type the preview isn't working (No preview available.) even if I use paragraph field as a rendered entity on the default layout.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇯🇴Jordan Abdelrahman Amer Amman

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.

  • 🇨🇷Costa Rica keboca

    I had the same problem, but I've found a way to solve it (at least for me). Basically, I added a new \Drupal::moduleHandler()->alter() right after the cloned parent renders the parent field within the

    \Drupal\paragraphs_previewer\ControllerParagraphsPreviewController::paragraphsPreviewRenderParentField

    method.

    It allows me to alter the "$parent_view_mode" variable in order to render the same way as the module does but using another view mode that I've created only to render the correct field in the proper way. In a nutshell, I just rerun this line: $elements = $parent_clone->{$parent_field_name}->view('paragraphs_preview');

  • 🇪🇸Spain idiaz.roncero Madrid

    Same here, I noticed that this module nevertheless DOES use a config that is not exposed via an admin UI (a module settings form) but exists:

            $parent_view_mode = \Drupal::config('paragraphs_previewer.settings')->get('previewer_view_mode');
    

    So, if you are using the full view mode via Layout builder, you are doomed... unless you manually change the exported paragraphs_previewer.settings.yml and manually set your preferred view mode.

    A solution proposal would be the following:

    1. Expose a module settings form that allows the developer to choose a different view mode
    2. Better errors: trigger a warning if the view mode in use is using layout builder in order to let the developer know what's happening, and/or instead of No preview available. print something like It seems the view mode you are using to render this paragraph is using Layout Builder, which is unsupported. Please use the module settings to switch to a different view mode.
  • "I'm encountering a similar issue when using the Paragraphs Previewer module alongside Paragraphs Layouts. Instead of seeing no preview available, I get the following error: 'Call to undefined method Drupal\layout_paragraphs\Form\InsertComponentForm::getEntity() in Drupal\paragraphs_previewer\Controller\ParagraphsPreviewController->onForm() (line 55 of modules/contrib/paragraphs_previewer/src/Controller/ParagraphsPreviewController.php).

Production build 0.71.5 2024