Summary
The CSS cache builder (dxpr_theme_css_cache_build()) runs twice on every theme settings save — once before and once after the form is processed. This is acknowledged in theme-settings.php:118 with the comment @todo come up with a less 'icky' solution.
The double execution exists as a workaround for a Drupal form processing quirk where theme settings values aren't yet available during the initial form submission handler.
Improvements
- Faster settings save: With 20+ color schemes and extensive typography options, eliminating the redundant build halves the CSS generation time on save
- Simpler code: Removing the workaround makes the settings save flow easier to understand and maintain
- Reliability: The current approach creates a fragile dependency on execution order; a single post-save rebuild is more predictable
Risks
- The replacement solution must ensure that CSS is rebuilt with the new settings values, not stale ones
- Custom/sub-themes that override
theme-settings.php may need to be aware of the change
- Must verify that the CSS cache file is correctly written for all theme setting combinations
Involved components
theme-settings.php — form submit handler and cache rebuild trigger
dxpr_theme_callbacks.inc — dxpr_theme_css_cache_build() function
config/install/dxpr_theme.settings.yml — default settings
Optional: Intended side effects
Potential approaches:
- Use a
#submit handler that runs after system_theme_settings_submit() to ensure new values are saved before rebuild
- Use a
KernelEvents::TERMINATE subscriber to defer the rebuild until after the response is sent (non-blocking)
- Use a
drupal_register_shutdown_function() callback for simplicity
Summary
The CSS cache builder (
dxpr_theme_css_cache_build()) runs twice on every theme settings save — once before and once after the form is processed. This is acknowledged intheme-settings.php:118with the comment@todo come up with a less 'icky' solution.The double execution exists as a workaround for a Drupal form processing quirk where theme settings values aren't yet available during the initial form submission handler.
Improvements
Risks
theme-settings.phpmay need to be aware of the changeInvolved components
theme-settings.php— form submit handler and cache rebuild triggerdxpr_theme_callbacks.inc—dxpr_theme_css_cache_build()functionconfig/install/dxpr_theme.settings.yml— default settingsOptional: Intended side effects
Potential approaches:
#submithandler that runs aftersystem_theme_settings_submit()to ensure new values are saved before rebuildKernelEvents::TERMINATEsubscriber to defer the rebuild until after the response is sent (non-blocking)drupal_register_shutdown_function()callback for simplicity