Switching theme seems to block custom module preprocess_block hook

Created on 11 July 2023, over 1 year ago

Problem/Motivation

I need to switch theme selection for a subset of content nodes with specific URL aliases (creating a microsite of sorts).
Implementing this switches the theme as expected for the page nodes, however several custom blocks - installed via a custom module - use the preprocess_block hook to add CSS styling to the theme, specifically for the blocks.
When switch_page_theme is used, and the page is in layout builder - edit mode, the hook gets called as expected.
When switch_page_theme is used, but the page is not in edit mode, the hook does not get called.
When switch_page_theme is not used, and the page is in edit mode, the hook gets called as expected.

Switch page theme therefore seems to block the execution of the preprocess_block hook, but only outside of layout builder.

Steps to reproduce

  1. Create a custom module, with a custom block and a preprocess_block hook function.
  2. Enable/install the custom module
  3. Add the block to a given page content node.
  4. Use switch page theme to override the theme for the page (adding URL alias).
  5. Enable Xdebug and use an IDE of your choice
  6. Place a breakpoint on the first line of the preprocess_block hook
  7. Visit the content page in a browser
  8. Note that the breakpoint wasn't hit
  9. Disable switch page theme on the page content node (just target some other url)
  10. Refresh the content page in a browser - see it render with a different theme
  11. If xdebug is set up correctly, the breakpoint in code should be hit, confirming that the preprocess_block hook is called

Proposed resolution

Please fix this, or I will need to find an alternative switch theme solution

Remaining tasks

To fix it

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: cannot reproduce

Version

4.0

Component

Code

Created by

🇬🇧United Kingdom pardy_man

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

Comments & Activities

  • Issue created by @pardy_man
  • Status changed to Closed: cannot reproduce over 1 year ago
  • 🇬🇧United Kingdom pardy_man

    Ignore this, the root cause actually turned out to just be a naming convention issue that tied to the hook to a specific theme name. The issue wasn't related to this theme switcher specifically

Production build 0.71.5 2024