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?