I am trying to use this Media Library form field in a custom block inside Layout Builder.
I have declared my form field this way:
$form['test_media_image'] = array(
'#type' => 'media_library',
'#allowed_bundles' => ['image'],
'#title' => 'Test Media Library',
'#description' => '',
'#default_value' => $config['test_media_image'] ?? null,
'#required' => false,
);
I am able to set an image from the Media Library; however, when I try to remove or update the image, it doesn't work.
When I click Remove, an small image appears with the message 'Removing {image name}', but the image remains there.
I've included some logs in your module and can assure that the removeItem function is called and then the processMediaLibrary function, but
I see that the element id is different in both cases.
In the removeItem function, I get this element["#id"]: edit-settings-test-media-image--ywfPbsnEXns and in the processMediaLibrary this different element["#id"]: edit-settings-test-media-image--67mlSTSMapE.
Also, below the image there is this message "The maximum number of media items have been selected".
Comments
Comment #2
slozada_dev commentedComment #3
millerrs commentedI also have this issue. It appears the changes to the valueCallback method made in alpha7 are the culprit.
Comment #4
rene bakxI had the same issue but the fourth patch of #3102729 fixed my problem.
Comment #5
EricRondo commentedI have a similar issue, but it also occurs outside of Layout Builder.
I made a custom block with a media_library form field in its configuration. When an image has been selected/saved it can't be deleted anymore, neither inside layout builder nor in simple block configuration (admin/structure/block/manage/...).
Another issue with Layout Builder is that it use the front theme for rendering, so it doesn't embed the Media CSS for the field and the modal. I tried with this module but the rendering is still not very satisfying. Any ideas ?
Comment #6
nightlife2008 commentedI'll close this issue in favor of https://www.drupal.org/project/media_library_form_element/issues/3102729
The scope of this module does not account for frontend theme rendering; you could look into Media Library Theme Reset.