psy Posted April 3 Share Posted April 3 (edited) I've tried all sorts of hooks, before & after in my module and checked out how other modules do stuff, including TraceDebugger, which inserts scripts very early in the process. Tracy is the only hook I've found that inserts scripts before the user logs in. I've tried "ProcessWire::ready" "Page::render" "AdminTheme::getExtraMarkup" My hooks never fire. I do not want to create a new AdminTheme or have to manually change any admin template files What I'm trying to achieve is that a Guest who lands on the admin login page sees some extra rendered HTML. Any suggestions? Found the answer by studying the code in TracyDebugger on how to load methods that aren't ready in an autoload module and with Bernhard's suggested hook. See below posts for more info. Edited April 5 by psy solved Link to comment Share on other sites More sharing options...
bernhard Posted April 3 Share Posted April 3 It depends on where exactly. Or what exactly you want to modify. All backend requests call /site/templates/admin.php, so you can do something like this there (BEFORE the final require statement): wire()->addHookAfter('ProcessLogin::execute', function ($event) { $event->return = 'before' . $event->return . 'after'; }); edit: oh, and you can add scripts/styles there as well: $url = rockfrontend()->url(__DIR__ . '/admin.js', true); wire()->config->scripts->add($url); /** @var Config $config */ require($config->paths->core . "admin.php"); 1 1 Link to comment Share on other sites More sharing options...
psy Posted April 3 Author Share Posted April 3 Thanks @bernhard I was aiming to load some scripts and add some html programmatically via my module to the admin login screen. I saw your post about injecting module js via $config->scripts but I think it assumes the user is already logged in and all autoload modules are ready. I couldn't get it to fire on the admin login screen, even with an after ProcessWire::ready hook, as a guest user. If I can't achieve it programmatically via the module api, I can add the instructions to manually add the code to admin.php before the require($config->paths->core . "admin.php"); as per your suggestion Link to comment Share on other sites More sharing options...
bernhard Posted April 3 Share Posted April 3 Ah sorry didn't see you are trying it from within a module. The hook that I shared should work there as well. Your module needs to be an autoload module. So I'd do this: add my hook in /site/templates/admin.php and check if it works add my hook in /site/templates/ready.php - it should work as well add my hook in your module's init() method - it should work as well If it doesn't work place a " bd('fired') " or whatever in your module's init() method and check if that dump shows up on the login screen. If not, then your init() is not triggered on that pageload. 2 Link to comment Share on other sites More sharing options...
psy Posted April 3 Author Share Posted April 3 On 4/3/2025 at 9:54 AM, bernhard said: If not, then your init() is not triggered on that pageload. Expand I think that's the problem. The hook is in the module init() but as the user is a guest, the autoloaded module isn't ready, even with the After ProcessWire::ready hook. The way I read the docs, autoloaded modules should be ready at this point. I'm obviously missing something. I tried a bd() call but the user isn't logged in. Will check again from an incognito window with the Tracy Debugger guest dumps in a window in which I'm logged in. Cheers to @adrian for this tip ๐ 1 Link to comment Share on other sites More sharing options...
bernhard Posted April 3 Share Posted April 3 It looks like your autoload module is not autoloading ๐ Maybe you changed the "autoload" prop to true after installing the module? Then you need a modules refresh to make sure ProcessWire recognises that change and loads your module on every request. On 4/3/2025 at 10:07 AM, psy said: I tried a bd() call but the user isn't logged in. Will check again from an incognito window with the Tracy Debugger guest dumps in a window in which I'm logged in. Cheers to @adrian for this tip ๐ Expand Just set "forceIsLocal" of tracy to true and you'll have tracydebugger enabled even for guest users. This is what I'm using in all my projects in my config-local.php: // tracy config for ddev development $config->tracy = [ 'outputMode' => 'development', 'guestForceDevelopmentLocal' => true, 'forceIsLocal' => true, 'localRootPath' => getenv("TRACY_LOCALROOTPATH"), 'numLogEntries' => 100, // for RockMigrations 'editor' => 'windsurf://file/%file:%line', ]; 2 Link to comment Share on other sites More sharing options...
psy Posted April 4 Author Share Posted April 4 On 4/3/2025 at 12:35 PM, bernhard said: Just set "forceIsLocal" of tracy to true and you'll have tracydebugger enabled even for guest users. Expand Hi Bernhard, it's a super feature for most applications but it doesn't work with http requests. The FE TracyDebugger bar script gets tagged onto the end of the request and results in a JSON error. It was Adrian's suggestion to monitor guest dumps in another window that saved me. I tested your hook is /site/ready.php and it worked a treat! I then went back to TracyDebugger to see how Adrian handled it and found the answer. The method wasn't ready. Lifted Adrian's code from TD and adjusted it to suit my needs, ie in TracyDebugger init(): // log requests for Request Logger $this->wire()->addHookAfter('ProcessWire::ready', function($event) { if(!method_exists($event->page, 'render')) { $event->page->addHookAfter('render', $this, 'logRequests'); } }); $this->wire()->addHookAfter('Page::logRequests', $this, 'logRequests'); Learning from the masters all the time ๐ 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now