7

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?

7

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.

8

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.

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

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

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

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. – Ashish Deynap Jan 9 '17 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. – 4k4 Jan 9 '17 at 7:21

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.