processwire-requests
processwire-requests copied to clipboard
Hook In AdminThemeFramework to modify styles/scripts array by modules
Hook to modify $config->styles or $config->scripts, in AdminThemeFramework
Need to be able to hook right before the styles and scripts are output in order to change the order (e.g. move to the front a specific CSS file), or remove. This can be done by making getHeadJS() hookable, or getBrowserTitle() hookable; only need to hook into that method because once hooked am only reading what is in the $config->styles FilenameArray and doing some stuff with that.
With Reno theme i can hook into getExtraMarkup because that is being called before any output ($adminTheme->getExtraMarkup();); but this doesn't work in the new UiKit Admin Theme;
Optional: Steps that explain the enhancement
- Once the method is hookable then modules can manipulate the admin styles and scripts.
- I am using this for my Font Awesome 5 Pro module that lets me use FA5pro icons in the admin
- I grab the contents of $config->styles, iterate through them and if strpos 'font-awesome' i remove that or move it to the top (prepend) it so that it can be overridden by the FA pro styles that come after.
Current vs. suggested behavior
No hook
Why would the enhancement be useful to users?
Useful to module authors that need to manipulate the styles and scripts right before output, mostly to move or remove/replace things.
Optional: Screenshots/Links that demonstrate the enhancement

@outflux3, GetExtraMarkup is hookable (https://github.com/processwire/processwire/blob/b087149c4071d88a590ec144daf2e9117855bf92/wire/core/AdminTheme.php#L316), so perhaps this feature request can be closed?
I'll check to see if it works with the module in question (FontAwesomePro) and that the method is called before any output, so that the scripts & styles can be manipulated in an array.
@outflux3, any news on this?
No, the problem is not solved;
GetExtraMarkup is not called in the _main.php or _head.php;
There is no way for me to modify the contents of the $config->styles before they output.
In reno the getExtraMarkup is called before output.

@outflux3 At the top of the AdminThemeUikit _main.php file is a call to renderExtraMarkup('x'): https://github.com/processwire/processwire/blob/master/wire/modules/AdminTheme/AdminThemeUikit/_main.php#L25
That renderExtraMarkup() calls the getExtraMarkup() method. I'm wondering if it might seem like it's not getting called first because it's getting called twice? So maybe you are only seeing the 2nd one, which is called during <head> rather than before it. I think you could make your hook run just the first time by using a static variable or class variable (if in a module), i.e.
static $hello = false;
if($hello) return;
$hello = true;
// your code here
Another option is your hook could remove itself after running the first time, so that it only runs once.