English version was created automatically using Drupal module auto_node_translate and free DeepL translator.

How to display available methods again when using Drupal and Kint modules for Drupal 8 or Drupal 9

zveřejněno 2020-08-20

For Drupal 9, you can no longer install the devel module version 8.x-2.1. Instead, version 4.0.0 is now available, but it has removed the Kint submodule. Fortunately, there is a Devel Kint Extras module that restores the original functionality.

Our goal is simple, for development it is often useful to see the available methods of an object. For Drupal 8 this was easy, the Devel module and the Kint submodule showed it all. The new Drupal 9 compatible version has already removed the Kint submodule, see. "Remove Kint module and create a kint dumper plugin in devel" https://www.drupal.org/project/devel/issues/2839515

In the release notes of version 4.0.0 https://www.drupal.org/project/devel/releases/4.0.0 we read that we need to run composer require kint-php/kint to get kint back, but it only half works, as this way kint doesn't return available methods - it works like a classic dump.

Kint missing methods

Happily, this is all solved by the new Devel Kint Extras module https://www.drupal.org/project/devel_kint_extras.

Installation and Configuration

So we install both Devel I Devel Kint Extras modules, ideally via composer. The latter will also automatically download the necessary kint-php project.

At this point I ran into the problem that I had previously had the 4.x-dev version of the Devel module, and after changing to 4.0.0, the devel.info.yml file did not list the version of the module needed by Devel Kint Extras. I just deleted the web/modules/contrib/devel directory, and reloaded it via composer.

Kint missing dependency

In the "Devel settings" /admin/config/development/devel setting, just switch Dumper to "Kint extended" and you're done.

Kint with methods

If we want to dump a user entity, for example, we use ksm($account); and get 

Devel dumper

Warning: we need to use ksm() or dpm(), not kint().

There is a trick for Kint to limit the depth of the dumps so we don't run out of memory. Put the following lines in web/sites/default/settings.php (or settings.local.php ...):

// Change kint max_depth setting.
if (class_exists('Kint')) {
  // Set the max_depth to prevent out-of-memory.
  \Kint::$max_depth = 4;
} https://gist.github.com/JPustkuchen/a5f1eaeb7058856b7ef087b028ffdfeb#gi…

Conclusion

With the Devel Kint Extras module, we can easily bring back to Drupal 9 what we were used to from the previous version of the Devel and Kint module for Drupal 8.