Problem/Motivation

When saving a block in Layout Builder that uses the Media Library dialog, the AJAX request runs under the admin theme. This prevents the Layout Builder preview from rendering correctly in the frontend theme. Additionally, admin theme callbacks (such as gin_form_after_build) are not loaded, which leads to errors like:

TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "gin_form_after_build" not found or invalid function name in call_user_func_array() (line 1085 of /var/www/html/docroot/core/lib/Drupal/Core/Form/FormBuilder.php).

Steps to reproduce

  1. Open a Layout Builder page for a node.
  2. Add a block that contains a Media Library field (opens in a dialog).
  3. Save the block configuration.
  4. Observe that the preview blocks may render incorrectly.

Proposed resolution

We no longer rely on the AJAX request’s theme, since it may originate from the admin theme. Instead, we conditionally load the admin theme callbacks using loadAdminThemeCallbacks() to ensure that form callbacks like gin_form_after_build() are available, preventing errors while still allowing the Layout Builder preview to render in the frontend theme.

Remaining tasks

  • ✅ File an issue about this project
  • ✅ Addition/Change/Update/Fix to this project
  • ✅ Testing to ensure no regression
  • ➖ Automated unit/functional testing coverage
  • ➖ Developer Documentation support on feature change/addition
  • ➖ User Guide Documentation support on feature change/addition
  • ➖ UX/UI designer responsibilities
  • ➖ Accessibility and Readability
  • ✅ Code review from 1 Varbase core team member
  • ✅ Full testing and approval
  • ✅ Credit contributors
  • ✅ Review with the product owner
  • ✅ Update Release Notes and Update Helper on new feature change/addition
  • ✅ Release varbase-10.1.0-beta1, varbase_layout_builder-10.2.0-beta3

Varbase update type

  • ✅ No Update
  • ➖ Optional Update
  • ➖ Forced Update
  • ➖ Forced Update if Unchanged

User interface changes

  • N/A

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • #3545316 Fix: Theme negotiator rendering Layout Builder preview blocks after saving a block using Media Library dialog By: n.ghunaim
CommentFileSizeAuthor
#6 3545316-5.patch2.83 KBn.ghunaim
#4 3545316-4.patch2.79 KBn.ghunaim
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

n.ghunaim created an issue. See original summary.

n.ghunaim’s picture

Status: Active » Needs review
n.ghunaim’s picture

StatusFileSize
new2.79 KB
n.ghunaim’s picture

Status: Needs review » Needs work
n.ghunaim’s picture

StatusFileSize
new2.83 KB
n.ghunaim’s picture

Status: Needs work » Needs review
rajab natshah’s picture

Title: Fix theme negotiator rendering Layout Builder preview blocks after saving a block using Media Library dialog » Theme negotiator rendering Layout Builder preview blocks after saving a block using Media Library dialog

rajab natshah’s picture

rajab natshah’s picture

Issue summary: View changes
rajab natshah’s picture

rajab natshah’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

rajab natshah’s picture

Issue summary: View changes

Status: Fixed » Closed (fixed)

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