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!
#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 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