Why Choose Devel For Your Drupal Site?

Blog Article

Why Choose Devel For Your Drupal Site?

 August 9th, 2019

Devel has been around since 2003.  It has been downloaded over 3.5 million times, and it runs on more than two hundred thousand websites.  Devel, being one of the most popular and invaluable tools for constructing and coding sites, contains developer and debugging utilities to help ensure more efficiency during the most common development tasks.

Features

Cache clear                  Config editor               Container Info             Current route info       Element Info

Entity Info                   Events Info                  Execute PHP               Field Info                    PHPinfo()

Rebuild Menu             Reinstall Modules       Routes Info                  Run cron                     State editor

Theme registry            View Session

dprint_r()

The dprint_r function is a tool for peeking inside of a Drupal array to see what's there.  It formats the array into a human-readable paragraph, rather than just displaying all the variables one after the other in an endless and mostly incomprehensible strand-like PHP's print_r() function would do.  There are several ways to implement it, and all of them require the devel module to work.

Sometimes, depending on where your particular module falls in the core's own build process, you might be able to generate a fatal error by trying to call dprint_r() from inside your own module.  Even if devel exists, it might not be fully rendered as a set of PHP functions yet. If this happens to you, move this code snippet inside one of your module's functions rather than leaving it naked at the top of your module, and the error will stop.

Controlling Placement On The Page

You can generate the printed array into a block, into a footer, or into a $messages box, like the "login successful" message that Drupal prints out automatically when a user logs in.

Toolbar

Devel is now directly integrated into the core Toolbar module.  Visible links are configurable.  When in vertical mode, the Toolbar shows links to all the available features.

Services, Routing & Events

Drupal 8 adds a lot of new concepts and structures that developers need to understand to build new modules.  Devel now provides report pages for services, routing, events, and many more.

Manage Configuration & State

You can use Devel to inspect and edit both systems.

Switching Users

This feature is the same as in Drupal 7.  Devel provides a block that allows a quick switch between users.

Twig Extension

The Twig engine in core allows module developers to add new functions and filters to be used in templates (HTTP:// twig.sensiolabs.org/doc/2.x/advanced.html).  Devel adds three new Twig functions for template developers:

devel_dump($var)                               devel_message($var)                           devel_breakpoint()

Devel_Dump

Prints a complex data structure in an attractive way, the same as PHP function kpr().  Without arguments, devel_dump will display the full Twig context.

Devel_Message

Prints a complex data structure in an attractive way in the message area, the same as PHP function dpm(). Without arguments, devel_message displays the full Twig context.

Devel_Breakpoint

Forces the PHP interpreter to stop the same way as setting a breakpoint in an IDE. Available variables are in $context array. Actually, it works only with xDebug.

Dumpers

Devel now provides a way to replace the tool used for formatting and displaying the variables inspected through the debug functions. Dumpers are implemented using the new plugin system in core. Some of these plugins require external libraries to be enabled. Those libraries have to be installed with Composer.  Available Dumpers:

Doctrine debug (the default one) uses DoctrineCommonPersistenceProxyDebug class

Drupal variable uses DrupalComponentUtilityVariable class Symfony var-dumper uses

SymfonyComponentVarDumperDumperHtmlDumper class

ChromePHP uses the ChromePhp debugging tool

FirePHP uses the FirePhp debugging tool

Kint (in a sub-module, needs to be enabled) uses DrupalkintPluginDevelDumperKint class

Symfony Var-Dumper

If the var-dumper module is present and enabled, the class used by the dumper became DrupalvardumperPluginDevelDumperVarDumper, which provides more integration with Drupal data structures.  Class names become links to the relative class in IDE (if configured).  User roles become links the role edit page.

Adding A Dumper

Dumpers are plugins; contrib modules can add new dumpers to the system.  ExampleDumper.php has to be in the PluginDevelDumpernamespace.  Every dumper needs to implement the DevelDumperInterface interface or extend the DevelDumperBase class.

Webprofiler

The old Devel query logger and memory profiler has been removed in favor of a new sub-module: Webprofiler

Realtime Data

The report pages that Devel shows about services routing and so on lists all data available on a Drupal website. Webprofiler instead collects data about the rendered page, so it is useful to measure performance data and to debug every single response. The available data collectors are:

Assets              Blocks             Cache              Config             Database                      Devel               Events

Extensions       Forms              Http                 Mail                 PHP Config                 Performance Timing

Request           Routing           Services           State                Theme                         Timeline          User

Views

Integration With Xhprof

Webprofiler collects a high-level Drupal data structure.  For example, if we need PHP function level data, we need a hierarchical profiler like XHProf (or Tideways for PHP > 7.x).  The Drupal XHProf module adds a new data collector for Webprofiler

Conclusion

As you can see from its extensive features, Devel is an invaluable tool for constructing and coding websites.  It has developer and debugging utilities to help ensure more efficiency during the most common development tasks.  If you are a website developer, you should consider using Devel for all of your Drupal site development.

View More Articles