Drupal - How to make use of Devel debugging functions on large or complex objects

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;
}

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 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).

Or

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

Tags:

Debugging

8