6 Ways to Debug Drupal 8

Back in 2011, the development of Drupal 8 began. Since then, thousands of web developers around the world have been looking forward to the release of a brand-new version of this well-known content management system. In November 2015, Drupal 8 was released and developers were able to explore its features.  The 8th Drupal version kept and significantly improved all the best features from the previous versions. This user-friendly tool provides new opportunities for data structuring, website customization, and content presentation. Besides that, it opens new mobile development and multilingual accessibility horizons. Powered by Symfony2, it is a great choice for web development. However, writing excellent code is still immensely difficult, and getting it perfect the first time is almost impossible. You can save your project from most potential issues if you work independently. But if you are working with a large enterprise solution built by many developers over the years, you need to be an expert in Drupal 8 debugging techniques. Take a look at the best ways to improve your code and use this article as your Drupal debugging handbook! Read also: Drupal 9 release. #1: Disable Cache in Drupal Settings Drupal 8 has expanded its functionality due to volumetric caching (rendered Twig templates and blocks) and Varnish as caching server for excellent performance. With every change we make, we run the risk of being forced to rebuild the site cache from scratch. Solutions? We know three ways to address Drupal 8 debug effectively: 1) Clear Cache It will allow you to visualize changes and progress. You can clear the cache manually every time by going along this path: Configuration - Performance - 'Clear all caches'. 2) Use Drupal Twig Debug Drupal 8 is enriched with an out-of-the-mode debugging feature. You can enable this feature to debug your code. Add a few lines of code either in the sites/default/service or development.service file. parameters: Why is Drupal Twig Debug Effective? search refinement (you can quickly determine which part of your HTML code was written in which Twig templates) easy to find matching sentence templates, and you can easily override them parameter debug: true, which turns on the Twig debugging process and starts displaying the used Twig templates along with their paths 3) Drupal 8 Local Development Setup  Step 1. Copy the file /sites/example.settings.local.php to file /sites/default/settings.local.php This file already has the necessary settings. Step 2. In the file settings.php uncomment the following lines, this will include  created settings.local.php: Step 3. Check that this line is uncommented in settings.local.php:  The development.services.yml file has already been created, you only need to include  it. Step 4. You also need to check that in settings.local.php CSS and Javascript aggregation disabled: Step 5. You need to disable caching of rendered HTML and the cache of the Dynamic Pages module: Step 6. To prevent Drupal 8 from picking up tests from modules, you need to change the value of this setting to FALSE: Step 7. You need to add the following lines  to /sites/development.services. yml: As a result, development.services.yml should look like this: Step 8. After that, you need to clear the cache, which can be done via Drush: drush cr Struggle with Drupal 8 debugging? Our Drupal developers will be eager to help!   #2. Connect the Devel Module The Devel module in Drupal 8 is a quick and easy way to start debugging. Drupal Devel module consists of two submodules: Kint and Drupal 8 Web Profiler. Here are the main functions of Kint and Drupal 8 web profiler: #3. Use the Drupal Console We don't forget about the powerful Drupal CLI, which allows you to: creating code for creating themes and modules interacting with the Drupal installation debug code in your Drupal 8 web project  Thanks to the power of the Symfony Console and its third-party components, the Drupal Console provides you with a vast range of Drupal debugging commands. By the way, you can use any command with the term "debugging," but we recommend using the following parameters. #4. Use PHPStorm for Drupal Debugging If none of the above methods of Drupal debugging is suitable for you, you can use a paid commercial PHPStorm IDE for your Drupal project. It integrates perfectly with the Drupal and Xdebug codebase! Xdebug is a more complex, advanced debugging technique than the slightly simpler, faster, and easier-to-use Drupal development module. It is one of the best Drupal debugging ways that allows you to add a breakpoint to your PHP code and perform systematic actions as the Drupal query is executed. Also, with Xdebug, you get easy access to your variables. You can visualize which ones are available at a particular time. Do you need help with PHPStorm? AnyfoSoft is ready to assign our dedicated PHP developers to your tasks! You need to figure out how to configure Xdebug in PhpStorm properly! PhpStorm is an IDE that can also help you with debugging. It launches the autofill function for hooks. In addition, there are many additional PhpStorm plugins to improve the code, such as PHP Annotations, Drupal Symfony Bridge, etc. Don't forget to enable Symfony integration before using PhpStorm. What about the best JS IDEs? Read our article to know all about powerful code environments for your project! #5. Drupal Error Log and Warnings Display As you may remember, one of the features of Drupal 7 is that you can customize the list of issues on display. You can choose Drupal 8 debug mode for different options. Drupal performance logging is your powerful problem checker.  #6. Drupal 8 Logger  The introduction of Drupal error log was a significant difference between Drupal 7 and 8. With the database logging module, you can log messages to the database. The watchdog() function is an integral part of the process. In Drupal 8, this module is also present. However, it is improved and is known as the Drupal 8 logger class. It creates a copy of the logger service and is useful for debugging purposes. What is the difference between logger in the 7th and 8th versions? We studied how the functionality has changed. Final Thoughts So how can you debug Drupal 8? Reference this list of easy-to-implement techniques to obtain the best results and create excellent Drupal debugging. Using suitable modules, it becomes easier to ensure that the frontend and backend web development is of the highest quality possible. Xdebug and PHPStorm can be your best assistant tools during this process. Also, the Drupal development module, Drupal error log, Drupal 8 debug mode, and Web Profiler will be great ways to make the debugging process quickly and more powerful for both sides. Now the way to debug the Drupal 8 website isn’t a problem!  If you have any questions about Drupal 8 development and debugging, we are ready to help! 
Read more

What Are the Best WordPress Alternatives for 2021?

Thunder & Lightning: Best Drupal Distributions for Media and Publishing

Best Drupal Hosting: Comparison of Acquia Cloud, Platform sh, DigitalOcean, Amazee.io, and Pantheon hosting

The Business Case: Drupal 8 to Drupal 9 Migration

Drupal Commerce: New Features and Innovations that will Define the Industry In 2021

How to Hire a Drupal Developer: the Ultimate Guide

Drupal Layout Builder. How We Built a Platform with Color/Theme Management

Your Drupal Multisite for B2B - a Business-Efficient Shortcut

Drupal 9 Release: Features and Upgrade Tips

Be in touch with us!