megclaypool
10/23/2018 - 9:10 PM

Limit kint levels in Drupal 8

[Limit kint levels in Drupal 8]

According to the developers: Kint "...[is] var_dump() and debug_backtrace() on steroids. Easy to use, but powerful and customizable. An essential addition to your development toolbox." Which is all 100% true :) (Note that in order to use kint, you must install the Devel module, and enable the optional Kint submodule.) However, kint has a tendency to crash your site if it gets caught in a sad loop of a field referring to its parent node referring to its child field referring...

To prevent sad crashes, you can limit the levels of kint and thus its memory demands by pasting the following into your site's settings.php file:

### New Kint, using Devel module 4.x and up

```
// Change kint max_depth setting.
if (class_exists('Kint')) {
  // Set the max_depth to prevent out-of-memory.
  \Kint::$max_depth = 4;
}
```

----

### Old Kint, using Devel < 4.0
...

require_once DRUPAL_ROOT . '/modules/contrib/devel/kint/kint/Kint.class.php';
Kint::$maxLevels = 3;
// you can change the max levels to whatever you like, in order to balance whatever you need to be able to see with not crashing your local dev site

...