In theme_preprocess functions (e.g. theme_preprocess_block, theme_preprocess_menu, etc) there is the $variables argument.

In Drupal 7 I could look at this variable using devel module and typing dpm($variables).

How I can do that in Drupal 8?

I tried kint, dump and var_dump, but for all of them I get a fatal error memory exhausted.

  • If there's not enough memory for var_dump, PHP (or your server) might just need more memory. If that's impossible there are some creative workarounds here: stackoverflow.com/questions/5446647/…. Limiting the output level via xdebug might be the easiest – Clive Mar 5 '18 at 20:53

The best way would probably be a breakpoint with xdebug turned on. Which requires configuration efforts though.

What I was normally doing in similar cases was a step-by-step approach. I was printing out $variables keys first and then narrowing my var_dump with a specific key. E.g. var_dump($variables['key']). Slowly but surely.

In the end I think that in terms of efforts it is way better to set up debugger and use breakpoints to inspect variables.

| improve this answer | |
  • Good idea to log only the keys at first... It's unfortunate that simple debugging and looking into the black box, requires so much configuration efforts in Drupal. Makes it quite difficult to learn by diggin in and getting your hands dirty... – olli Aug 19 at 17:32

Best approach for this is to use print step by step. Use echo ''; var_dump($variables); This will fetch the result in readable format.

| improve this answer | |

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.