Subscribe To Our NewsLetter
Share This Post:
Are you working on a Drupal website and being tormented by a storm of issues? If the answer is yes, just know that you are not alone. Anyone who offers Drupal development services, be it a Drupal development company or an individual freelancer, encounters these issues during the development, deployment, or maintenance stage.
Now, is your mind being boggled by the question, “Then, how do they manage to sail through the challenges they come across?” The answer lies in some sureshot debugging techniques that help in eradicating any issues you encounter while building or working on a Drupal site.
Drupal 9 Debugging Techniques You Should Know
Disabling cache in Drupal settings:
Drupal 9 is known for caching blocks, rendered twig templates, and many other things. However, this is not always beneficial as while coding it becomes quite challenging if the results load from the cache. The latest changes aren’t visible which leads to frustration and you can only view them if you clear the cache. This implies that if you aspire to quickly see the changes without clearing the cache, it is crucial for you to disable the cache.
Enabling twig debugging
Enabling twig debugging helps in showing the template path, template suggestions, and hook suggestions.
If you want to enable twig debugging, simply go to sites/default/services.yml and set the values of debug and auto-reload to true.
Use {{ dump () }} inside the twig template to have the variables print.
Leveraging PHP functions for printing variables
Using the Devel module’s Kint
When it comes to Drupal 9, installing the Devel module 8.x-2.1 isn’t possible. This is because it has been replaced by 4.0.0 without the submodule Kint. But, Devel Kint Extra is an additional module that possesses the original functionality. It is important to remember that the Devel Module is a pre-requirement for using the Devel module’s Kint feature. Besides, you’ll have to install the Devel Kint Extra module through composer:
composer require kint-php/kint
Kint:
kint($node);
This code will help you dig into the properties of the node. In case you want to expand the arrays on the same page, you can click on the + sign as shown in the image.
In case you want to open a particular array in a new tab of your browser, simply click on the right-sided icon.
It is crucial to note that due to Kint’s configuration, you may face an error out of memory. However, there is no need to worry as you can use the following code to override it.
// Change kint max_depth setting.
if (class_exists('Kint')) {
// Set the max_depth to prevent out-of-memory.
\Kint::$max_depth = 4;
}
You can also use {{ kint() }} to print variables in Twig templates
ksm
ksm($node)
dpm
Static class properties and available methods are also helpful in debugging. You can access them from Devel settings by following the path /admin/config/development/devel. Then, select Kint extended and you’ll get access to Static class properties and available methods too.
Using Web Profiler
Web Profiler works wonders in tackling performance issues.
Given below is how the web profiler bar appears at the bottom of the page. Through it, you can access different types of information including Drupal version, php configurations, performance timings, forms, routes, and cache. These can be highly effective in increasing site and page performance.
Furthermore, you can also set what you want to be visible on the web profiler through the path: /admin/config/development/devel/webprofiler.
By clicking on any item on the web profiler, you can get directed to a new page that summarizes all the information for that item.
Let’s Wrap Up
Bugs and errors are an integral part of Drupal development. Every Drupal development company struggles with them. However, what sets eminent organizations apart from the rest is their exceptional knowledge of Drupal debugging techniques. Throughout the blog, we discussed 5 effective Drupal debugging techniques that aid in bug resolution and performance improvement of websites and applications.
In case you find it challenging to implement any of them, just remember that LN Webworks is always there to help you out. We are a reputed Drupal development company with a team of proficient developers who possess unparalleled knowledge about incredible Drupal debugging techniques. So, whenever you find yourself stuck, reach out to us without any second thoughts.
Share This Post:
Author Information
LN Webworks
Your Drupal Solution PartnerLN Webworks have championed open-source technologies for nearly a decade, bringing advanced engineering capabilities and agile practices to some of the biggest names across media, entertainment, education, travel, hospitality, telecommunications and other industries.
Talk With Certified Drupal experts !!
Related Articles
December 18, 2023
Why is Drupal the Top Choice for Big Organizations: Top 8 Reasons
July 12, 2022