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
インストール
composer require 'drupal/devel:^5.5'
概要
Develモジュールは、Drupal開発者やサイト構築者に不可欠なツールキットで、幅広いデバッグおよび開発ユーティリティを提供します。変数の検査、デバッグ出力の表示、バックトレース情報の確認、SQLクエリの直接ブラウザ上での確認などの機能があります。
主な機能として、Entityの内部プロパティを検査するためのデバッグタブの追加、アクティブな設定値を変更するための設定エディタ、State APIを管理するためのState変数エディタ、コンテナサービス、ルート、イベント、要素、テーマレジストリデータを表示するための包括的な情報ページがあります。
モジュールはDrupalツールバーと統合され、キャッシュクリア、cron実行、メニュー再構築などの開発者ツールへのクイックアクセスを提供します。また、開発中のデバッグを容易にするために、送信メールをファイルにリダイレクトするメールシステムも含まれています。
付属のDevel Generateサブモジュールは、Node、ユーザー、タクソノミーターム、メニュー、メディア、カスタムBlockを含むテストコンテンツの一括作成を可能にし、開発およびステージング環境に現実的なサンプルデータを投入するのに非常に便利です。
Features
- 変数検査用デバッグ関数: dpm()、dvm()、dpq()、ddebug_backtrace()、ddm()
- すべてのEntityタイプに自動追加されるEntityデバッグタブで内部プロパティを表示
- アクティブな設定オブジェクトの表示、編集、削除が可能な設定エディタ
- Drupal State API変数の表示・変更が可能なStateエディタ
- 登録されたすべてのサービスとパラメータを表示するコンテナサービスインスペクター
- 登録されたすべてのルートと詳細を表示するルート情報ページ
- ディスパッチャ内のすべてのイベントリスナーを一覧表示するイベント情報ページ
- すべてのrender element定義を表示する要素情報ページ
- 利用可能なレイアウトを表示するレイアウト情報ページ(layout_discoveryが有効な場合)
- テーマフック定義を確認するためのテーマレジストリビューア
- 現在のセッションデータを表示するセッションビューア
- テスト中に他のユーザーになりすますためのユーザー切り替えBlockとページ
- キャッシュクリア、cron、メニュー再構築へのクイックアクセスを備えたツールバー統合
- 送信メールを送信せずにファイルに保存するメールロギングシステム
- Twigテンプレートデバッグ関数: devel_dump()、devel_message()、devel_breakpoint()
- 設定可能なバックトレース表示を備えたカスタムエラーハンドラ
- 権限ページとモジュールページでのマシン名の表示
- 'debug'タグを使用したhook_query_TAG_alter経由のクエリデバッグ
- 変数出力を強化するSymfony VarDumper統合
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
/admin/config/development/devel
Configure the main Devel module settings including variable dumper selection, error handlers, and display options.
/admin/config/development/devel/toolbar
Configure which menu items are always visible in the devel toolbar tray.
/devel/config/{filter}
Browse, filter, and edit active configuration objects in the system. Allows direct modification of configuration values in YAML format.
/devel/state
View and edit Drupal State API variables. Shows all state variables with their current values and provides edit links.
/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.
/devel/container/service
Displays all services registered in the Symfony service container with detailed information including class, arguments, and tags.
/devel/container/parameter
Displays all parameters registered in the Symfony service container.
/devel/routes
Displays all registered routes in the site including path, controller, requirements, and options gathered from .routing.yml files and route subscribers.
/devel/events
Displays all events and their listeners registered in the Symfony event dispatcher.
/devel/elements
Displays all render element types available in the system with their properties and default values.
/devel/entity/info
Displays information about all entity types including their handlers, keys, and links.
/devel/field/info
Displays information about field storage, field instances, bundles, field types, formatters, and widgets.
/devel/theme/registry
Displays the complete theme registry with all theme hook definitions.
/devel/session
Displays the contents of the current user's PHP session variable.
/devel/layouts
Displays all layouts available through the Layout API (requires layout_discovery module).
/devel/switch-user
Provides a form to search for and switch to another user account for testing purposes.
/admin/config/development/generate/content
Bulk generate test nodes with configurable content types, authors, comments, and various options.
/admin/config/development/generate/user
Bulk generate test user accounts with configurable roles and options.
/admin/config/development/generate/term
Bulk generate taxonomy terms with configurable vocabulary, depth, and translation options.
/admin/config/development/generate/menu
Bulk generate menus and menu links with configurable depth and link types.
/admin/config/development/generate/media
Bulk generate media entities with configurable media types and options.
権限 3
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
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 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.
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.
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.
You may have multiple error handlers selected. The 'Standard Drupal' handler and backtrace handlers can both display messages. Select only the handlers you need.
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.
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.