Preview mode in Layout Builder doesn't show anything

Created on 8 August 2024, 5 months ago

Problem/Motivation

When a salesforce_mfw block instance is added via Layout builder, when the Preview option is selected,
there is no indication that the block is there.

Steps to reproduce

1) Add a salesforce_mfw block via layout builder
2) Enable `Preview Content` under `Display Options`
3) No indication that the block is there.

Proposed resolution

Add some type of preview text

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States kyleleber

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

Comments & Activities

  • Issue created by @kyleleber
  • πŸ‡ΊπŸ‡ΈUnited States kyleleber
  • πŸ‡ΊπŸ‡ΈUnited States kyleleber
  • πŸ‡ΊπŸ‡ΈUnited States FrankieD3

    I've stumbled upon this issue and figured I'd toss in the solution I used for core cases. The issue stems from core, but Gin Layout Builder β†’ makes it a bit easier to notice.

    Simply put, the method for determining if the preview is empty sees it as nonempty. The contextual editing link is still present, but in your case, Gin Layout Builder has not reserved space for it.

    See #3239899 πŸ› Blocks do not have placeholders in Layout Builder Needs work for an explanation as to what's going on, and follow #953034 🌱 [meta] Themes improperly check renderable arrays when determining visibility Needs work for the main issue.

    My solution was to add a library to my front-end theme that I would only enqueue on Layout Builder pages with Gin Layout Builder overrides. See below.

    The CSS included in the library:

    .layout-builder-block {
      min-height: 48px;
    }
    

    Including the library:

    /**
     * Implements hook_page_attachments_alter().
     */
    function your_theme_page_attachments_alter(array &$attachments) {
      $is_layout_builder_active = \Drupal::routeMatch()->getRouteObject()->getOption('_layout_builder');
      $is_gin_lb_enabled = \Drupal::moduleHandler()->moduleExists('gin_lb');
      if ($is_layout_builder_active && $is_gin_lb_enabled) {
        $attachments['#attached']['library'][] = 'your_theme/gin-layout-builder-overrides';
      }
    }
    
Production build 0.71.5 2024