Allow layout builder blocks to be optional depending on whether the required context exists

Created on 24 May 2019, almost 6 years ago
Updated 7 February 2023, about 2 years ago

Problem/Motivation

In panels on drupal 7, if a required context didn't exist the pane involved would not be displayed and no error would be thrown. While this might not be ideal behaviour, it did have some good uses. If you wanted to display a particular profile if the user had that profile but show nothing if they didn't or if you wanted to show og membership information if a membership existed.

In layout builder a MissingValueContextException is thrown very early on in the process of rendering a section and prevents the whole page being loaded.

Ideally it would be good if some blocks (maybe all blocks?) would just not render when contexts were missing, rather than breaking the whole page.

Possible Solutions

  1. Improve #2916876 and add a 'Context Has Value' condition. The current patch uses a EventListener on \Drupal\layout_builder\LayoutBuilderEvents::SECTION_COMPONENT_BUILD_RENDER_ARRAY but this runs too late to avoid the error thrown by SectionComponentBuildRenderArrayEvent::__construct
  2. Wrap each iteration of the loop in Section::toRenderArray() in a try/catch.
Feature request
Status

Needs work

Version

10.1

Component
Layout builder 

Last updated 3 days ago

Created by

🇬🇧United Kingdom rlmumford Manchester

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.

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    #14 means needing a follow up of some kind? That can just be a referenced issue here.
    IS could use some tweaks also, of the possible solutions which was chosen? All of them?

  • 🇺🇸United States azinck

    Patch 15 rerolled for 10.3.x.

Production build 0.71.5 2024