Quick tips on using Devel and Kint for Drupal 8 debugging

Posted on January 20th, 2016 in Drupal

In the Drupal 8 Devel module, a wrapper for the Kint debugging tool is included. This needs to be enabled in addition to Devel, and provides a stylish replacement for the Krumo output found in the Drupal 7 version.

To debug variables and objects withDevel and Kint, use one of various print methods: dpm(), dsm(), kpr(), kprint_r() in core or contrib (php) code:

Example:

<?php
    dsm($object);
?>

Navigation tips are found in the Kint documentation, but some of the most useful for quick navigation are:

Click anywhere in the collapsed area to show contents. If using keyboard navigation, press right arrow (Enable keyboard navigation first by pressing “d”):

Collapsed Object in Kint

 

Click the plus sign to expand all subs. If using keyboard navigation (Enabled with “d”), press the right arrow key twice:

Expanded Object in Kint

 

Click the arrow to the right to open a sub object or array in a new window:

Kint open sub object in new window

 

Add new comment

The content of this field is kept private and will not be shown publicly.

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.