1

In Drupal 7 this worked:

drupal_add_js("jQuery(document).ready(function () { console.log('Hello!'); });", 'inline');

which aims to print the messages from the PHP code onto DevTools JS console in realtime (on each page request), however in Drupal 8 the above function has been removed in favor of #attached.

I'm aware that I should use #attached in my library, but sometimes the $form is not accessible and I'd like to invoke some JS code on certain functions and conditions (e.g. in hook_tokens) for debugging purposes (like injecting some PHP variables into the JS message during the processing).

Is there any other way of doing this?

0

Sometimes the $form is not accessible and I'd like to invoke some JS code on certain functions and conditions for debugging purposes.

Not sure if this will do for you, but posting this anyways just in case.

I use Greasemonkey for Firefox and Tampermonkey for Chrome which allows your browser to load any js file that you write locally on this app/your computer.

  • It's handy, but I mean to print the messages from the server side, so I can also inject some backend variables from PHP and print them onto DevTools console. – kenorb Jul 21 '17 at 8:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.