Problem/Motivation

The form is rendered in the site theme ignoring the module settings

Steps to reproduce

  1. Go to Layout builder page
  2. Start adding a block from the Media field
  3. Click the Add media button
  4. screenshot

  5. See the styles, theme hooks, and try select any media
  6. No media is added after you select and insert it
CommentFileSizeAuthor
Selection_378.png42.76 KBmiroslav-lee
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

miroslav-lee created an issue. See original summary.

miroslav-lee’s picture

Status: Active » Needs review
mark_fullmer’s picture

Status: Needs review » Active

Although I would love for the theme switch to be as easy as using Drupal's ThemeNegotiator approach, I do not believe this, on its own, will be sufficient. My understanding is that this is because the ThemeNegotiator requires the context of the route to determine what the theme should be (see related discussion at #2292217: ThemeNegotiator::determineActiveTheme() should not require a RouteMatch to be passed in), and since the Layout Builder Modal and the Media Library are initiated outside of the context of a route, they cannot reliably be designated to use a theme via ThemeNegotiator.

Specifically, this conundrum is discussed in #3050508: Media library loads front-end theme when invoked from settings tray.

As confirmation of this, when I functionally test this merge request, I do see that some of the CSS provided by the selected theme does appear to load, presumably because it was loaded during previous route match (such as layout_builder.add_block), but in the context of the modal itself, the theme is not actually being used. To give one example, inspecting both the HTML markup produced in that context or the CSS loaded for .ui-dialog .ui-dialog-titlebar shows that the active default theme, rather than an administrative theme is used.

This problem is why Layout Builder Modal has gone to such lengths to implement the course of action indicated in https://www.drupal.org/project/drupal/issues/3050508#comment-13522943 , as can be seen in the not insignificant amount of CSS it is adding to the active theme.

Fortunately, there is another contributed module that provides the solution to what is reported here: https://www.drupal.org/project/media_library_theme_reset

Again, if I'm missing something about the potential for the ThemeNegotiator to be sufficient here, please *please* correct me, as that would be a much simpler resolution!

If you agree with the above analysis, let's go ahead and mark this issue as "Closed (works as designed)."

miroslav-lee’s picture

Status: Active » Closed (works as designed)

Thank you a lot for your answer.
The module which you recommend works.