
Common Drupal 10 Module Development Mistakes and How to Fix Them
Pooja Neharkar
SEO Specialist
Pooja is an experienced SEO Specialist and Digital Marketing Expert passionate about boosting online visibility and driving organic growth. She excels in on-page, off-page, and technical SEO, Google Ads, and Facebook Ads, helping brands rank higher and reach the right audience. With a data-driven and creative approach, & delivers measurable results that make a real impact.
Drupal 10 is one of the most advanced, secure, and flexible CMS frameworks available today. With its Symfony foundation, strict coding standards, and modular architecture, Drupal gives developers immense control. But this power also means that even the smallest mistakes in custom module development can break functionality, cause routing failures, trigger YAML errors, or lead to unexpected site behavior.
Whether you're a beginner or an experienced developer transitioning from Drupal 8/9 to Drupal 10, understanding common pitfalls can save hours of debugging. As a Drupal development company, we’ve seen how these issues affect real-world projects. In this guide, we’ll explore the most frequent Drupal 10 module development mistakes and show you exactly how to fix them, using clear explanations and practical examples.
1. Misunderstanding the Drupal 10 File & Folder Structure
Many issues in Drupal 10 module development start with the basics: incorrect folder structure.
Common Problems
- Module directory name not in lowercase
- Missing essential files
- Mixing PSR-4 namespaces
- Incorrect placement of controller, plugin, or form classes
- Module visible in the UI but not functioning due to file misplacement
Drupal 10 follows strict PSR-4 autoloading, meaning your directory structure must match your PHP namespaces perfectly.
Correct Structure Example
my_module/
my_module.info.yml
my_module.module
src/
Controller/
DemoController.php
Form/
Plugin/
config/
install/
schema/
How to Avoid This Mistake
- Always name your module folder in lowercase snake_case.
- Place all PHP classes inside src/ with correct namespaces.
- Do not place controllers inside root or custom folders.
- Validate autoloading by clearing the cache and checking the logs for “Class Not Found” errors.
A well-structured module ensures clean autoloading, fewer Symfony errors, and predictable behavior across environments.
2. Incorrect .info.yml or .module Files
The .info.yml file tells Drupal what your module is, and even a single misplaced space can break it.
Typical Errors
- YAML indentation issues
- Missing required keys like type or core_version_requirement
- Incorrect dependency declaration
- Typos in the module machine name
These cause the module to:
- Not appear on the Extend page
- Throw YAML parsing errors
- Break due to missing dependencies
Correct .info.yml Example
name: My Custom Module
type: module
description: Provides custom functionality for the site.
core_version_requirement: ^10
package: Custom
dependencies:
- drupal:node
How to Fix
- Use spaces only, never tabs.
- Validate YAML using online tools or yamllint.
- Ensure dependency names match exact machine names.
A clean .info.yml is the foundation of a functional Drupal module.
3. Routing Errors in Drupal 10
Routing is one of the biggest pain points for Drupal developers. One incorrect indentation or namespace can make the entire route fail.
Common Routing Mistakes
- Incorrect controller namespace
- Missing access permission
- Using deprecated routing formats
- YAML syntax errors
- Forgetting _controller or _title keys
Correct Routing Example
my_module.demo:
path: '/my-module/demo'
defaults:
_controller: '\Drupal\my_module\Controller\DemoController::content'
_title: 'Demo Page'
requirements:
_permission: 'access content'
How to Fix Routing Issues
- Check logs for “RouteNotFoundException.
- Use: drush debug:router to inspect routes.
- Ensure controller namespace matches file path exactly.
- Use unique route names to avoid collisions.
Proper routing ensures your pages load, controllers respond, and Drupal’s menu system works correctly.
4. Incorrect Dependency Injection (DI)
Drupal 10 follows modern PHP practices, which means services should be injected, not called globally.
Common DI Mistakes
- Using \Drupal::service() inside methods
- Forgetting to update constructors after adding new services
- Missing entries in my_module.services.yml
- Incorrectly extending base classes
Correct Way to Implement DI
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory')
);
}
Fix Tips
- Inject services in constructors, not methods.
- Always register custom services in .services.yml.
- Match class namespaces exactly.
Correct DI improves:
- Testability
- Performance
- Code readability
5. Improper Use of Drupal Hooks
Hooks remain useful in Drupal 10, but many developers:
- Use incorrect hook names
- Place hooks in the wrong files
- Continue using deprecated hooks from Drupal 7/8
Correct Example
function my_module_help($route_name, RouteMatchInterface $route_match) {
return 'Custom help text here.';
}
Best Practices
- Hooks MUST be in .module file only.
- Use event subscribers when replacing deprecated hooks.
- Check Drupal API docs for the latest changes.
6. Ignoring Drupal Coding Standards
Drupal coding standards ensure consistency and readability.
Common Issues
- Missing type hints
- Incorrect file comments
- Long unstructured methods
- Violating PSR-12
How to Fix
Use automated tools:
phpcs --standard=Drupal
phpcbf --standard=Drupal
Follow best practices:
- Apply SOLID principles
- Use clean, modular classes
- Keep functions focused and small
Clean code prevents technical debt and improves long-term maintainability.
7. Not Clearing Cache After Code Changes
Drupal’s caching system is powerful—but it can mislead developers.
Symptoms
- Routes not updating
- Hooks not firing
- Templates not refreshing
- Services not loading
Fix
Run:
drush cr
For Twig issues:
drush cache:rebuild
Tip
Enable Twig debug mode during development for easier template debugging.
8. Incorrect Permissions & Access Control
Access control mistakes break routing and block users from using module features.
Common Mistakes
- Missing custom permissions
- Incorrect _permission naming
- Overly permissive routes
Fix
Add custom permission:
access my module page:
title: 'Access My Module Page'
Use in routes:
requirements:
_permission: 'access my module page'
Good permission design improves security and usability.
9. Configuration Schema & Config API Errors
Drupal’s configuration API is strict. Missing or incorrect schema files trigger warnings.
Common Issues
- Missing config/schema folder
- Invalid schema keys
- Wrong config naming
- Direct database edits instead of using the config API
Fix
Validate configuration using:
drush config:validate
Always separate configuration into:
- config/install
- config/optional
Follow schema rules to prevent invalid or missing configuration.
10. Ignoring Logs & Debugging Tools
Beginners often focus on front-end errors, ignoring the real debugging goldmine: Drupal logs.
Debug Tools You Must Use
- /admin/reports/dblog
- drush ws
- Xdebug
- Symfony Profiler
- PHPStorm debugger
These tools catch:
- Routing failures
- Class not found errors
- YAML syntax issues
- Permission errors
- Deprecated API usage
Logs reveal everything you need to fix module errors quickly.
11. Writing Slow or Unoptimized Code
Even fully functional modules can slow your site if the code is inefficient.
Common Performance Issues
- Heavy database queries
- No caching
- Unnecessary entity loads
- Rendering large lists without pagination
Fix
- Use EntityQuery instead of loadMultiple()
- Use cache tags, contexts, and max-age
- Add lazy builders to heavy elements
Result: faster modules, better performance, and reduced server load.
12. Not Writing Tests
Skipping tests leads to fragile modules that break during upgrades or deployments.
Types of Drupal Tests
- Unit tests
- Kernel tests
- Functional tests (BrowserTestBase)
Why Tests Matter
- Prevent regressions
- Make updates safer
- Ensure stable CI/CD workflows
Tested modules stand the test of time—especially during major Drupal upgrades.
Conclusion
Drupal 10 is modern, secure, and highly flexible—but only when modules follow best practices. By avoiding these common mistakes—routing errors, YAML issues, wrong file structure, DI problems, caching confusion, permission failures, and poor debugging—you can build clean, optimized, high-performance custom modules that scale reliably.
If you adopt the recommended practices—proper DI, code standards, configuration schemas, caching strategies, and automated testing—you’ll not only reduce bugs but also create modules that are easier to maintain and upgrade in the future.