I am having trouble making real use of Devel's debugging functions kint() and dpm() in my modules and twig templates. They work fine for primitive variables, flat arrays and such, but if I want to inspect into some object like an EntityRerefenceFieldItemList they either cause the site to crash (white page) or generate so much data such that the scripts for expanding the list no longer work.

How do I circumvent these problems?

5 Answers 5


When working with entities and fields, you want to see the values, not the objects.

For an entity, use $entity->toArray(), for a field object, use $field->getValue(). You can transform that almost 1:1 to accessing those values on an object, e.g. $entity->field_name->property.

A few things are not shown there, for example computed properties like ->entity on an entity reference field. See https://wizzlern.nl/drupal/drupal-8-entity-cheat-sheet for an overall introduction.

That said, I'd also strongly recommend an IDE + xdebug over any debugging functions, I only use that and sometimes a simple debug(), which works just fine on the value arrays returned by the methods mentioned above.


The first problem can temporarily get fixed by changing the max array/object levels Kint will go deep. Currently this still has to be done by changing one line of code in the module. Though there already is an issue https://www.drupal.org/node/2405179 to make this a configurable setting.

In devel/kint/kint/config.default.php change 7 to any number you are fine with. I usually set it to 4.

/** @var int max array/object levels to go deep, if zero no limits are applied */
$_kintSettings['maxLevels'] = 7;

Remember that this number will get reset as soon as you update the Devel module.

Update: Now I found this beautiful snippet to simply be placed in your settings(.local).php. No hacking or patches needed.

// Change kint maxLevels setting:
include_once(DRUPAL_ROOT . '/modules/contrib/devel/kint/kint/Kint.class.php');
if (class_exists('Kint')) {
  // Set the maxlevels to prevent out-of-memory.
  Kint::$maxLevels = 4;

The Devel module is a great tool, however it does not work for every situation. There actually a module for debugging twig known as Twig XDebug(which i have not implemented yet).


Get xdebuger manually installed with your IDE.

Freely Available IDE's:

  • Netbeans

  • Eclipse

  • Aptana Studio (Eclipse derivative)

Paid IDE's:

  • phpDesigner

  • Jetbrains PHPStorm

  • Komodo IDE (has some free/flexible pricing scenarios).

Next Steps to be followed after choosing an IDE.

  1. Install Xdebug

  2. Modify your php.ini config to enable xdebug

  3. Install your IDE, configure to use xdebug and a browser.

  4. Possibly a browser plugin for xdebug. Ex- Xdebug helper for Chrome

  • For the first part: currently also devel provides XDebug integration for Twig templates with function {{ devel_breakpoint() }}. see here
    – marco
    Jan 10, 2017 at 7:57

Be careful with mouse clicks, don't click on the + icon! This expands all levels, which can take a long time. If you click on the title bar, you only expand the top level.

Drupal 8 Debugging: Kareful Klicking in Kint

  • I think it is not about clicking '+' sign on left most corner of kint but it's actually the casee when size of object is so heavy that it breaks the page in between the process of rendering and it get a blank white page. Jan 9, 2017 at 2:15
  • This is about the last part of the question: "...or generate so much data such that the scripts for expanding the list no longer work." - The rest is covered perfectly by the other answers.
    – 4uk4
    Jan 9, 2017 at 7:21

Add to settings.local.php or to settings.php

Kint V3

if (class_exists('Kint')) {
  // Change the maximum depth to prevent out-of-memory errors.
  \Kint::$max_depth = 4;

Kint V4 (Might also work with V5, untested).

if (class_exists('Kint')) {
  // Change the maximum depth to prevent out-of-memory errors.
  \Kint::$depth_limit= 4;
  • Oh, great. This looks like the answer I was looking for almost 7 years ago. :) I might be working on that project again soon, so I will definitely try this solution. Thanks!
    – Hendrik
    Dec 24, 2023 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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