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

Created on 3 December 2023, 12 months ago
Updated 24 May 2024, 6 months ago

Problem/Motivation

Error when custom blocks on cloned pages have media library fields, and we want to update the media on the cloned page:

An AJAX HTTP error occurred.
HTTP Result Code: 403
Debugging information follows.
Path: /media-library?destination=/node/365/layout&_wrapper_format=drupal_ajax&ajax_form=1&media_library_opener_id=media_library.opener.field_widget&media_library_allowed_types%5Bimage%5D=image&media_library_selected_type=image&media_library_remaining=1&media_library_opener_parameters%5Bfield_widget_id%5D=field_background_image_desktop%3A-settings-block_form&media_library_opener_parameters%5Bentity_type_id%5D=block_content&media_library_opener_parameters%5Bbundle%5D=full_width_image_cta&media_library_opener_parameters%5Bfield_name%5D=field_background_image_desktop&media_library_opener_parameters%5Bentity_id%5D=317&media_library_opener_parameters%5Brevision_id%5D=679&hash=DFIR0-jxQRzOJNa-rFxonuXharUm4T4YWuXkREH-rs0&views_display_id=widget
StatusText: error
ResponseText: {"message":"Non-reusable blocks must set an access dependency for access control."}

Steps to reproduce

I am on Drupal version 10.1.6 and am using this module (v1.16). I can clone any nodes/pages and that all works fine. Most of my pages, if not all, are using layout builder where I can add custom block types to each page. I have multiple custom block types that are Entity Reference with reference type of Media and a Media type of Image. For example, I have a hero banner block type that has a media field to add a background image to the block.

Now let's say I clone a page with a hero banner block in it and then want to change the image on the newly cloned page.

1- open the layout builder (for the newly cloned page)

2- Find the block on the page, Click on the pencil icon, and choose "configure"

3- Remove the existing background image

4- Click on the "Add media" button to open the media library, and select the new image. Then click the "insert selected" button.

At this point nothing happens as you keep trying to insert the selected image (kind of like the video shown in this github issue). If you check the browser console thoguh, you see the error mentioned above.

I am not sure how I can resolve this error. This is happening with all my custom blocks that are using Entity Reference to Media library as a field. Could you please advise?

🐛 Bug report
Status

Active

Version

1.16

Component

Code

Created by

🇺🇸United States akbarBakhshi

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

Comments & Activities

  • Issue created by @akbarBakhshi
  • 🇪🇸Spain byParlon

    I have the same problem, have you found a solution?

  • 🇪🇸Spain javitan

    I'm having the same issue, but I'm not sure the issue is related with this module. I can create a new node, and then I'm having the same problem updating any image of any block with an image field inside. I'm using layout builder. Were you able to solve it?

  • 🇮🇳India Krishna Mishra

    Hi, If you are using group module try this patch.
    https://www.drupal.org/project/group/issues/3071489 🐛 Incorrect Access Check on Media Library RTBC

  • 🇮🇳India santhosh@21

    I also has the same issue in my site
    Did anyone got solution ?

  • 🇪🇸Spain javitan

    I avoided the problem using Entity Browser instead of the media library (changing it from the form display).

  • 🇮🇳India santhosh@21

    With Entity browser still there is an below error

    "\nAn AJAX HTTP error occurred.\nHTTP Result Code: 500\nDebugging information follows.\nPath: /layout_builder/update/block/overrides/node.232/0/second/6097a8ed-fd54-4a5e-b859-d17c3f6a9a1d?destination=/node/232/layout&_wrapper_format=drupal_dialog&ajax_form=1\nStatusText: error\nResponseText: The website encountered an unexpected error. Please try again later.TypeError: key(): Argument #1 ($array) must be of type array, null given in key() (line 424 of modules/contrib/entity_browser/src/Plugin/Field/FieldWidget/EntityReferenceBrowserWidget.php). Drupal\\entity_browser\\Plugin\\Field\\FieldWidget\\EntityReferenceBrowserWidget::processEntityBrowser(Array, Object, Array)\ncall_user_func_array(Array, Array) (Line: 1012)\nDrupal\\Core\\Form\\FormBuilder->doBuildForm('layout_builder_update_block', Array, Object) (Line: 1075)\nDrupal\\Core\\Form\\FormBuilder->doBuildForm('layout_builder_update_block', Array, Object) (Line: 1075)\nDrupal\\Core\\Form\\FormBuilder->doBuildForm('layout_builder_update_block', Array, Object) (Line: 1075)\nDrupal\\Core\\Form\\FormBuilder->doBuildForm('layout_builder_update_block', Array, Object) (Line: 1075)\nDrupal\\Core\\Form\\FormBuilder->doBuildForm('layout_builder_update_block', Array, Object) (Line: 1075)\nDrupal\\Core\\Form\\FormBuilder->doBuildForm('layout_builder_update_block', Array, Object) (Line: 449)\nDrupal\\Core\\Form\\FormBuilder->rebuildForm('layout_builder_update_block', Object, Array) (Line: 633)\nDrupal\\Core\\Form\\FormBuilder->processForm('layout_builder_update_block', Array, Object) (Line: 325)\nDrupal\\Core\\Form\\FormBuilder->buildForm(Object, Object) (Line: 73)\nDrupal\\Core\\Controller\\FormController->getContentResult(Object, Object)\ncall_user_func_array(Array, Array) (Line: 123)\nDrupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}() (Line: 592)\nDrupal\\Core\\Render\\Renderer->executeInRenderContext(Object, Object) (Line: 124)\nDrupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)\nDrupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber->Drupal\\Core\\EventSubscriber\\{closure}() (Line: 181)\nSymfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object, 1) (Line: 76)\nSymfony\\Component\\HttpKernel\\HttpKernel->handle(Object, 1, 1) (Line: 58)\nDrupal\\Core\\StackMiddleware\\Session->handle(Object, 1, 1) (Line: 48)\nDrupal\\Core\\StackMiddleware\\KernelPreHandle->handle(Object, 1, 1) (Line: 106)\nDrupal\\page_cache\\StackMiddleware\\PageCache->pass(Object, 1, 1) (Line: 85)\nDrupal\\page_cache\\StackMiddleware\\PageCache->handle(Object, 1, 1) (Line: 48)\nDrupal\\Core\\StackMiddleware\\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)\nDrupal\\Core\\StackMiddleware\\NegotiationMiddleware->handle(Object, 1, 1) (Line: 49)\nDrupal\\remove_http_headers\\StackMiddleware\\RemoveHttpHeadersMiddleware->handle(Object, 1, 1) (Line: 51)\nDrupal\\Core\\StackMiddleware\\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)\nDrupal\\Core\\DrupalKernel->handle(Object) (Line: 19)\n"

  • 🇪🇸Spain javitan

    I guess you are using a Entity Browser view on the widget settings, right?

    Also, on the form display you have changed the widget to use the Entity Browser.

  • 🇮🇳India Veershetty

    Hello, I am still facing the issue for drupal 9 when I try upload image in layout builder using media browser. Anyone found solution?

  • 🇧🇪Belgium R3m

    I have exactly the same problem with version 10.2.2

Production build 0.71.5 2024