Devel

A comprehensive suite of development and debugging tools for Drupal developers, providing functions for variable inspection, entity debugging, configuration editing, content generation, and developer-focused administration pages.

devel
151,727 sites
233
drupal.org

Install

Drupal 12, 11, 10 v5.5.0
composer require 'drupal/devel:^5.5'

Overview

The Devel module is an essential toolkit for Drupal developers and site builders that provides a wide range of debugging and development utilities. It offers functions to inspect variables, print debug output, view backtrace information, and examine SQL queries directly in the browser.

Key capabilities include adding debug tabs to entities for inspecting their internal properties, a configuration editor for modifying active configuration values, a state variable editor for managing the State API, and comprehensive information pages for viewing container services, routes, events, elements, and theme registry data.

The module integrates with the Drupal toolbar for quick access to developer tools like cache clearing, cron execution, and menu rebuilding. It also includes a mail system that redirects outbound emails to files for easy debugging during development.

The accompanying Devel Generate submodule enables bulk creation of test content including nodes, users, taxonomy terms, menus, media, and custom blocks, which is invaluable for populating development and staging environments with realistic sample data.

Features

  • Debug functions for inspecting variables: dpm(), dvm(), dpq(), ddebug_backtrace(), ddm()
  • Entity debug tabs automatically added to all entity types for viewing internal properties
  • Configuration editor for viewing, editing, and deleting active configuration objects
  • State editor for viewing and modifying Drupal State API variables
  • Container services inspector showing all registered services and parameters
  • Routes information page displaying all registered routes with details
  • Events information page listing all event listeners in the dispatcher
  • Element information page showing all render element definitions
  • Layout information page displaying available layouts (when layout_discovery is enabled)
  • Theme registry viewer for examining theme hook definitions
  • Session viewer displaying current session data
  • Switch user block and page for impersonating other users during testing
  • Toolbar integration with quick access to cache clear, cron, and menu rebuild
  • Mail logging system that saves outbound emails to files instead of sending
  • Twig template debugging functions: devel_dump(), devel_message(), devel_breakpoint()
  • Custom error handlers with configurable backtrace display
  • Display of machine names on permissions and modules pages
  • Query debugging via hook_query_TAG_alter with 'debug' tag
  • Symfony VarDumper integration for enhanced variable output

Use Cases

Debugging Variables in Code

Use dpm($variable) anywhere in your code to output the contents of a variable to the message area. This works in hooks, controllers, forms, and anywhere Drupal code runs. For database queries, use dpq($query) to see the full SQL with arguments substituted. For backtraces, use ddebug_backtrace() to see the call stack.

Debugging in Twig Templates

Use {{ devel_dump(variable) }} or {{ dpm(variable) }} in Twig templates to output variables. Use {{ devel_dump() }} with no arguments to see all available context variables. Use {{ devel_breakpoint() }} to set a breakpoint for XDebug debugging.

Inspecting Entity Internal Data

Visit any entity (node, user, term, etc.) and click the 'Devel' tab to view its internal properties, field values, and methods. For entities without canonical URLs, use /devel/{entity_type}/{entity_id} paths.

Testing as Different Users

Place the Switch User block in a region or visit /devel/switch-user to quickly switch between user accounts for testing permissions and access control without logging out.

Debugging Email Functionality

Configure Devel Mail Log as your mail system in settings.php to redirect all outgoing emails to files in the temporary directory. This lets you verify email content without actually sending messages during development.

Populating Development Environment

Use Devel Generate to quickly populate a development site with realistic content. Generate hundreds of nodes, users, terms, and menus with a single command like 'drush genc 500 --bundles=article,page'.

Exploring Container Services

Visit /devel/container/service to see all registered services, their classes, dependencies, and tags. Click on any service to see detailed information. Use 'drush dcs plugin.manager' to list services matching a prefix.

Finding Route Information

Visit /devel/routes to see all registered routes with their paths, controllers, access requirements, and options. Use the current route info link to see details about the route handling the current page.

Debugging Hooks and Events

Use 'drush fn-hook cron' to see all implementations of hook_cron and open one in your editor. Use 'drush fn-event kernel.request' to see all listeners for an event.

Managing Configuration During Development

Use the Config Editor at /devel/config to view and edit active configuration objects directly. This is useful for testing configuration changes without exporting/importing YAML files.

Tips

  • Use dpm($variable) for quick debugging - it returns the input so you can chain it: return dpm($result);
  • Add $query->addTag('debug') to entity queries to automatically output the SQL using dpq()
  • The debug log file (ddm()) persists across requests and is useful for debugging AJAX, cron, and background processes
  • Set 'rebuild_theme' during active theme development but disable it for normal development to improve performance
  • Use Drush commands for generating large amounts of content - they're faster than the web UI and support batch processing
  • The Switch User block can be placed in a sidebar for quick access during testing, even on non-admin pages
  • For production sites, ensure only trusted developers have 'access devel information' permission as it can expose sensitive data
  • Use the state editor to quickly test features that depend on state values without writing code
  • The Container Info pages are invaluable for understanding how services are wired together
  • Install drupal/navigation_extra_tools for seamless integration with the core Navigation module

Technical Details

Admin Pages 21
Devel settings /admin/config/development/devel

Configure the main Devel module settings including variable dumper selection, error handlers, and display options.

Devel Toolbar Settings /admin/config/development/devel/toolbar

Configure which menu items are always visible in the devel toolbar tray.

Config editor /devel/config/{filter}

Browse, filter, and edit active configuration objects in the system. Allows direct modification of configuration values in YAML format.

State editor /devel/state

View and edit Drupal State API variables. Shows all state variables with their current values and provides edit links.

Reinstall Modules /devel/reinstall

Uninstall and reinstall selected modules. This will delete module tables and configuration, execute hook_uninstall() and hook_install(), and set the schema version to the most recent update.

Container services /devel/container/service

Displays all services registered in the Symfony service container with detailed information including class, arguments, and tags.

Container parameters /devel/container/parameter

Displays all parameters registered in the Symfony service container.

Routes /devel/routes

Displays all registered routes in the site including path, controller, requirements, and options gathered from .routing.yml files and route subscribers.

Events /devel/events

Displays all events and their listeners registered in the Symfony event dispatcher.

Element Info /devel/elements

Displays all render element types available in the system with their properties and default values.

Entity info /devel/entity/info

Displays information about all entity types including their handlers, keys, and links.

Field info /devel/field/info

Displays information about field storage, field instances, bundles, field types, formatters, and widgets.

Theme registry /devel/theme/registry

Displays the complete theme registry with all theme hook definitions.

Session viewer /devel/session

Displays the contents of the current user's PHP session variable.

Layouts /devel/layouts

Displays all layouts available through the Layout API (requires layout_discovery module).

Switch user /devel/switch-user

Provides a form to search for and switch to another user account for testing purposes.

Generate content /admin/config/development/generate/content

Bulk generate test nodes with configurable content types, authors, comments, and various options.

Generate users /admin/config/development/generate/user

Bulk generate test user accounts with configurable roles and options.

Generate terms /admin/config/development/generate/term

Bulk generate taxonomy terms with configurable vocabulary, depth, and translation options.

Generate menus /admin/config/development/generate/menu

Bulk generate menus and menu links with configurable depth and link types.

Generate media /admin/config/development/generate/media

Bulk generate media entities with configurable media types and options.

Permissions 3
Access developer information

View developer output like variable printouts, query log, container services, routes, events, and other debugging information. This is a restricted permission that should only be granted to developers.

Switch users

Become any user on the site with just a click. This is a restricted permission that grants significant access and should be used carefully.

Administer devel_generate

Access the content generation forms to create test content, users, terms, menus, and media.

Hooks 2
hook_devel_dumper_info_alter

Alter devel dumper plugin information declared by other modules.

hook_devel_generate_info_alter

Alter existing properties for DevelGenerate plugins.

Drush Commands 12
drush devel:hook <hook>

List implementations of a given hook and optionally open one in your editor.

drush devel:event <event>

List listeners for a given event and optionally open one in your editor.

drush devel:services [prefix]

Get a list of available container services, optionally filtered by prefix.

drush devel:uuid

Generate a Universally Unique Identifier (UUID).

drush devel:reinstall <modules>

Uninstall and reinstall specified modules.

drush devel-generate:content [num] [max_comments]

Generate test content (nodes) with optional comments.

drush devel-generate:users [num]

Generate test user accounts.

drush devel-generate:terms [num]

Generate taxonomy terms.

drush devel-generate:vocabs [num]

Generate taxonomy vocabularies.

drush devel-generate:menus [num_menus] [num_links]

Generate menus and menu links.

drush devel-generate:media [num]

Generate media entities.

drush devel-generate:block-content [num]

Generate custom block content entities.

Troubleshooting 7
Debug output not appearing when using dpm()

Ensure you have the 'Access developer information' permission. Also check that your error reporting settings at /admin/config/development/logging allow errors to be displayed.

Twig debugging functions not working

Twig debugging functions require twig.config.debug to be TRUE. Enable this in development.services.yml and rebuild the container. The functions will return nothing if debug mode is off.

Switch user block not showing users

Ensure you have the 'Switch users' permission. The block shows recently active users - if there are few users, increase the list size in block configuration.

Devel Generate creates content but fields are empty

Field population uses FieldItemInterface::generateSampleValue(). If a field type doesn't implement this method properly, values won't be generated. Use --skip-fields to exclude problematic fields.

Error handlers showing duplicate messages

You may have multiple error handlers selected. The 'Standard Drupal' handler and backtrace handlers can both display messages. Select only the handlers you need.

Mail logging not capturing emails

Ensure you've configured the mail system in settings.php: $config['system.mail']['interface']['default'] = 'devel_mail_log'; and the debug_mail_directory is writable.

Theme registry page is slow or times out

The theme registry can be very large. This is normal - the page dumps all theme hook information which can be substantial on complex sites.

Security Notes 7
  • The 'access devel information' permission grants access to sensitive internal data including configuration, state, session data, and container services. Only grant to trusted developers.
  • The 'switch users' permission allows impersonating ANY user including administrators. This should only be granted on development/staging sites or to highly trusted users.
  • Never enable Devel module on production sites unless absolutely necessary. If required, strictly limit permissions.
  • The Config and State editors allow direct modification of system settings - misuse can break the site.
  • Debug output (dpm, etc.) can expose sensitive data if accidentally left in code deployed to production.
  • The mail logging feature writes emails to files - ensure the directory is not publicly accessible.
  • Devel Generate operations delete content when 'kill' option is used - use caution on sites with real content.