Welcome to my series of blogs about debugging in Drupal 8.
The reason why I decided to create this series is that a lot of Drupalists use 'legacy' ways of non-interactive debugging based on php-native commands like print_r()
, var_dump()
, debug_print_backtrace()
or commands provided by contributed modules or themes like dpm()
or dump()
inside of twig templates.
Even though it's completely valid to use these commands to quickly display the value of a random variable, and to do simple (re-)search based on that, they have significant drawbacks compared to real interactive debugging. To name a few:
Some of these drawbacks are even more significant in Drupal 8. The object-oriented structure in Drupal 8 means we are working with very complex objects (and they are complex for a good reason). However, a lot of people are 'scared' of the debugging setup. With excuses like 'printing a variable works everywhere,' or 'I don't have the time to set up debugging,' they opt for the quick variable dump approach to dig deeper into these structures, similar to how we used to do it in earlier Drupal versions.
I think it's definitely worthwhile to invest time into a proper debugging setup, as the investment will definitely yield significant returns in the long run. In addition, with modern tools like the PhpStorm and XDebug browser plugins, the debugging setup is already much simpler than it used to be.
In this series, I will show you the basic steps on how to to set up debugging on a few commonly used developer environments.
The truth is, we all use somewhat different setups. Some will use VMs, some will use local stacks. To make these tutorials easier to follow, I am going to use the same implementation approach (with adjustments to the specifics of each environment).
The use cases are the following:
Each use case requires a different debugging setup; I sorted them above according to complexity of this setup (first use case has the simplest complexity).
You will find the details for each of these use cases in followup blog posts, coming shortly.
The following environments will be used for the tutorials:
For use cases 3 and 4 I've chosen Drupal VM as a Vagrant-based full-featured enterprise development environment.
Even though the tutorials will be tested with the environments above, they should be applicable to different operating systems (Linux, Windows), albeit with slight changes. Keep in mind that on Windows you should be aware of the different path syntax and difficulties, and that the setup of supporting PHP tools like Drush or Drupal Console is assumed (since their setup would go beyond the scope of the series).
setup of supporting PHP tools like Drush or Drupal Console is assumed (since their setup would go beyond the scope of the series).If this content did not answer your questions, try searching or contacting our support team for further assistance.
Sun Mar 31 2019 01:07:39 GMT+0000 (Coordinated Universal Time)