When used with media_library an exception is thrown

Created on 9 February 2021, almost 4 years ago
Updated 9 August 2023, over 1 year ago

Problem/Motivation

When a block type has a media reference field that is using the media_library form widget (which opens a browser at the /media-library route), this exception is thrown when one tries to switch an image in a block placed via the section library:

Non-reusable blocks must set an access dependency for access control.

this happens because the access controller for media library checks access for updating the block, but since the block has no usage yet (as the layout hasn't been saved) the code in SetInlineBlockDependency::getInlineBlockDependency returns null, which triggers the exception:

  protected function getInlineBlockDependency(BlockContentInterface $block_content) {
    $layout_entity_info = $this->usage->getUsage($block_content->id());
    if (empty($layout_entity_info)) {
      // If the block does not have usage information then we cannot set a
      // dependency. It may be used by another module besides layout builder.
      return NULL;
    }

A temporary workaround is to immediately save the layout after adding sections from the library, and only then come back and try to swap images via the media library.

Steps to reproduce

  1. Add a media reference field to the basic content block, and set the form widget to use the media library
  2. Add a block with media to a section, and save that section to the section library
  3. Place this section somewhere, but don't save the layout yet
  4. Edit the block with the media, and try to change the media, this throws the exception (its in an ajax call, so one must look at the browser console to see the error.)

Proposed resolution

If cloned blocks aren't saved when a section is placed in a layout, then the media library and layout builder check access for create rather than update, and this error is avoided.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jhedstrom Portland, OR

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.

  • First commit to issue fork.
  • @abhaisasidharan opened merge request.
Production build 0.71.5 2024