Drupal Devel: A Complete Guide to Setup, Features, and Debugging

Drupal is known for its flexibility and power, making it a good choice for developers building complex websites. However, with the performance capability, you also need effective Drupal development tools to streamline workflow. This is where the Devel module comes into play, offering tools to generate dummy content, debug issues, etc.

In this blog, we’ll help you learn how to install and configure this module to make development efficient. We’ll also understand how professional Drupal developers use Devel for debugging and testing. So, with that, let’s begin!

What is Devel in Drupal?

The Devel module is a set of tools essential for Drupal developers to streamline their work and enhance the debugging process. It provides admin menu, helper functions, and additional development Drush commands for Drupal development. These functionalities make the development more efficient and effective.

Why is Devel essential for Drupal developers?

The Devel module is a valuable tool, offering a range of advantages that significantly enhance the Drupal development workflow. Here is a list of them:

Accelerated Development

The Devel Generate sub-module allows for quick sample data generation, saving time on content setup. Its debugging tools help identify and fix issues swiftly, reducing development time. This also helps you get more insights into Drupal’s internal workings, aiding in faster development.

Enhanced Debugging

It offers a variety of functions for inspecting variables, SQL queries, and backtraces, making troubleshooting easier. Devel module also helps you understand code behavior and pinpoint performance bottlenecks. This allows developers to identify issues quickly contributing to more robust code.

Improved Workflow

Devel offers various tools to streamline common development tasks, increasing productivity. By enabling thorough testing and debugging, Devel contributes to higher code quality. Plus, the ability to generate and manipulate content quickly increases its management efficiency.

By leveraging the Devel module effectively, Drupal development experts can build sites efficiently with better code quality.

Key Features of Devel Module

The Devel module in Drupal offers a comprehensive suite of tools that significantly enhance the development process. Here are the key features of the Devel module:

  • Debugging tools: Functions like dpm() to print variables, dpq() to print queries, and the Web Profiler for in-depth analysis of page requests.
  • WebProfiler: The WebProfiler provides insights into page requests, including performance metrics, database queries, and rendered output.
  • Built-in Kint Debugger: Kint is an advanced debugging tool that replaces traditional PHP debugging functions such as var_dump() and print_r().
  • Entity Inspection: Examine Drupal entities in-depth, viewing fields, relationships, and loaded values to understand data structures.
  • Devel Generate: Rapidly create sample content like nodes, users, and taxonomy terms for testing purposes without needing real data.
  • Performance Profiling: Measure the performance of different parts of your Drupal site to identify bottlenecks and optimize code for speed.
  • Custom Tool Development: You can build specialized tools for specific development tasks. This extends Devel’s functionality to fit your project’s needs.
  • Drush Integration: Offers Drush commands for common development tasks, streamlining your workflow.
  • Mail Redirection: Redirect outgoing emails to files for inspection and testing email functionality.   
  • Masquerading: Temporarily impersonate other users to test site functionality from different user perspectives.

These features enhance the way Drupal programmers debug and debug their code. It also lets them build custom tools and test sites, generate sample content, and more. That streamlines workflow and makes development rapid.

Want custom Drupal modules for your website?

How to Install and Configure the Devel Module?

The Devel module provides features for debugging, profiling, and optimizing your Drupal site. Here’s a step-by-step guide on how to install and configure the Devel module:

Step 1: Installation Using Composer

Open your terminal and navigate to the root directory of your Drupal project. Run the following command to require the Devel module via Composer:

$ composer require drupal/devel --dev

Step 2: Configuration

Navigate to Configuration -> Development -> Devel settings. Configure options like the default variable dumper, such as Kint, error reporting level, and other preferences.

Step 3: Configure Kint

If you plan to use Devel for variable debugging, Kint should be installed as a dependency. You can run the following command to install it:

$ composer require kint-php/kint --dev

Once the installation is complete, the “Kint” radio button must be visible under “Variables Dumper” on the “Devel Settings” page. If it’s not visible, clear the caches and reload the page.

Step 4: Configure Webprofiler

On the Devel configuration page, access WebProfiler by clicking on it. Then, configure the performance metrics to display (e.g., query times, cache hits). Set visibility options for different types of profiling information.

Step 5: Configure Devel Generate

In the Devel configuration page, click on Generate. Configure the types and quantities of content to generate (e.g., nodes, users, terms). You can also specify any additional options or constraints for the generated content.

Step 6: Configure Token Replacement

Go to the Devel configuration page and click on Token Replacement. Here, you can configure how tokens are handled and displayed for debugging purposes.

Step 7: Configure Theme Developer

In the Devel configuration page, click on Theme Developer. Using this module, you can enable or disable features that show theme functions and template suggestions.

By following these steps, you’ll have the Devel module installed and configured with some of its tools. This will make Drupal web development rapid and effective. To get your website built with such best practices, consider hiring Drupal developers.

How to Generate Dummy Content with Devel?

Devel Generate is a tool within the Devel module that allows you to quickly create sample content for testing purposes.

Method 1: Using Devel Generate

Devel Generate is a tool within the Devel module that allows you to quickly create sample content for testing purposes.

Step 1: Access Devel Generate

Navigate to your Drupal admin dashboard. Go to Administer -> Configuration -> Development -> Generate Content.

Step 2: Select Content Types

Choose the content types for which you want to generate dummy content. You can select multiple content types.

Step 3: Configure Settings

Here, you can set the configurations for generating the dummy content:

  • Number of Nodes: Specify the number of nodes to generate for each selected content type.
  • Date Range: Set the date range for the generated content’s creation date.
  • Other Options: Depending on the content type, you have options like generating comments, images, or specific field values.
  • Delete Existing Content: Be cautious when using the delete option, as it permanently deletes all existing content of the selected types.

Step 4: Generate Content

Click the “Generate” button to start the content generation process.

Example: To generate 100 nodes of content type “article” with a creation date range of the past month, follow these steps:

  • Go to Administer -> Configuration -> Development -> Generate Content.
  • Select the “Article” content type.
  • Set the number of nodes to 100 and choose an appropriate date range.
  • Click “Generate”.

This is an example that you can try to learn how to use Devel for generating content.

Method 2: Using Drush Command

You can use the Devel Generate tool for generating sample data, but it is not efficient. If you need more efficient content generation, you can use the Drush command. Here is the code:

drush genc <number_of_nodes> <max_comments_per_node> -y

Replace <number_of_nodes> and <max_comments_per_node> with the values you require.

This method is simple but needs familiarity with Drush commands.

By following any of the above methods, you can generate dummy content for testing purposes. It lets Drupal development company provide you with a tested site that works smoothly, enhancing user experience.

How to use Devel for Simple Debugging?

Devel offers several tools for simple debugging, but the most commonly used functions are dpm() and dpq().

  • dpm($variable): Prints a variable to the screen for inspection.
  • dpq($query): Prints a database query to the screen.

Here is a stepwise process to debug your code using Devel:

Step 1: Identify the Issue

Pinpoint the area of your code where you suspect a problem. Clearly define what you expect the code to do and what it’s actually doing.

Step 2: Use dpm() to Inspect Variables

Place the dpm() function within your code where you want to inspect a variable’s value. For example:

$node = Node::load(1);

dpm($node);

Running this command will output the contents of the $node variable to the page so you can examine its properties and values.

Step 3: Use dpq() to Inspect Queries

Use dpq() to inspect the SQL queries generated by your code. For example:

$query = db_select('node', 'n')

    ->fields('n', array('title'));

dpq($query);

This will print the generated SQL query to the screen, helping you identify potential issues with your query.

Step 4: Analyze the Output

Once you get the generated output by dpm() and dpq(), compare the actual and expected values. If you get any unexpected result, your code must have an error.

Step 5:  Refine Your Code

Based on the information gathered, make necessary modifications to code logic. Continue this process until the issues are resolved. That means you will get no error, and the actual value and the expected output will match.

By following these steps and using dpm() and dpq(), you can identify and resolve issues in your Drupal code.

FAQs About Drupal Devel

Is Devel safe to use on a production site?
No, Devel is primarily a development tool and should not be enabled on production sites due to security risks and performance impacts.
How can I improve performance using Devel?
Devel's Web Profiler can help identify performance by analyzing page load times, database queries, and other factors.
Can I create custom tools with Devel?
Yes, Devel provides a framework for building custom development tools. That allows you to build custom functionality for your specific project needs.

Conclusion

The Devel module stands out as a valuable tool in the Drupal developer’s toolkit. It accelerates development and simplifies debugging, leading to optimized code. By integrating Devel into your Drupal workflow, you can save time and improve site performance.

By installing Devel and configuring tools like Kint, Webprofiler, and Devel Generate, you leverage the complete power of Drupal. If you are seeking to build sites with best practices followed, hire Drupal developers.

Struggling with your Drupal website development?

author
Mayur Upadhyay is a tech professional with expertise in Shopify, WordPress, Drupal, Frameworks, jQuery, and more. With a proven track record in web development and eCommerce development.

Leave a comment