LayoutBuilderRestriction\EntityViewModeRestriction::inlineBlocksAllowedinContext doesn't check if the section storage is a view_display

Created on 2 December 2024, 5 months ago

Problem/motivation

\Drupal\layout_builder_restrictions\Plugin\LayoutBuilderRestriction\EntityViewModeRestriction::inlineBlocksAllowedinContext is called with a null display view for any section storage that isn't a view mode.

Steps to reproduce

  1. Enable layout_builder_restrictions and configure for view modes
  2. Install dashboard module (thas provides a section storage)
  3. Try to add a block to a dashboard, it will fail

Proposed resolution

layout_builder_restrictions has a global config for Layout Builder Restriction plugins, but can't be configured per section storage.
We would need to:
* Provide a way to configure that per section storage (e.g. view modes, dashboard, you name it)
* Add an appliesTo(SectionStorage $section_storage) to the plugin definitions.
* Each plugin needs to check it's applying to the proper section storage that it could apply (e.g. if !isset(display_view) => return).

This module uses Gitlab CI for automated testing of proposed code changes. To contribute code changes, create a merge request. Patch files will not trigger automated testing and are not sufficient for review.
πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain penyaskito Seville πŸ’ƒ, Spain πŸ‡ͺπŸ‡Έ, UTC+2 πŸ‡ͺπŸ‡Ί

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

Merge Requests

Comments & Activities

  • Issue created by @penyaskito
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks for reporting this, @penyaskito. We do have test coverage for integration with the Dashboards module (see DashboardsIntegrationTest.php), and I just tested this using the latest version of Drupal 10 with Dashboards 2.1.7, and was able to successfully add blocks to a Dashboard, so I'm probably doing different steps than you provided. Here's my annotated version of the steps to reproduce, as originally stated.

    1. Enable layout_builder_restrictions and configure for view modes. Enabled. On /admin/config/content/layout-builder-restrictions , the "Entity View Mode" plugin is enabled.
    2. Install dashboard module (thas provides a section storage). installed. On /admin/config/content/layout-builder-restrictions, now the "Dashboards View Mode" plugin is enabled (automatically).
    3. Try to add a block to a dashboard, it will fail. On /admin/structure/dashboards/add , I create a new dashboard, and use the Block restrictions to suppress Views blocks. I save. I click "Personalize". I see the Layout Builder interface. I successfully add a Section. I try to add a Block. I see that there are no Views blocks listed. I successfully add the Dashboard-provided "Add content" block.
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson
  • πŸ‡ΊπŸ‡ΈUnited States ACoolDevDude California

    Hello. I have run into this myself. To add to the original information, this is happening with the following versions:

    Drupal 11.1
    Dashboard 2.0.0
    Layout Builder Restrictions 3.0.1

  • Assigned to nidhish
  • Status changed to Postponed: needs info 2 months ago
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    Facing the same issue in the following scenario:

    Given that the Navigation and Layout Builder Retractions modules were enabled
    When I go to "/admin/config/user-interface/navigation-block" which is the Navigation blocks config page
    And I click on "Add block" in the navigation toolbar
    Then I see the following message

    Error message
    Oops, something went wrong. Check your browser's developer console for more details.

    When I open the browser debug tools
    Then I see the following error

    The website encountered an unexpected error. Try again later.
    
    Error: Call to a member function getThirdPartySetting() on null in Drupal\layout_builder_restrictions\Plugin\LayoutBuilderRestriction\EntityViewModeRestriction->inlineBlocksAllowedinContext() (line 279 of modules/contrib/layout_builder_restrictions/src/Plugin/LayoutBuilderRestriction/EntityViewModeRestriction.php).
    Drupal\layout_builder_restrictions\Controller\ChooseBlockController->build()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 638)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 54)
    Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle() (Line: 53)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
    Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
    Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
    Drupal\Core\DrupalKernel->handle() (Line: 19)
    
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    Attached a static layout_builder_restrictions--2025-02-12--3491116--mr-37.patch file from this point of MR37.
    To be used with Composer Patches

  • Pipeline finished with Success
    2 months ago
    Total: 372s
    #422127
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan
  • Pipeline finished with Skipped
    2 months ago
    #422406
  • πŸ‡ΊπŸ‡ΈUnited States mark_fullmer Tucson

    Thanks for adding the steps to reproduce, @rajab_natshah! The proposed new conditional check seems totally fine to accommodate edge cases in modules like Navigation and Layout Builder Retractions. Merged, with a new release on the way!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024