On a Drupal project, the task came up to output a custom list of articles with pagination and caching. The standard Views doesn't offer enough flexibility, and template hacks turn the code into spaghetti. The solution is developing a custom Drupal 10 module from scratch, with a well-thought-out architecture. Custom Drupal 10 module development requires knowledge of Drupal hooks, services, and plugins—this allows flexible extension of functionality: from unique blocks to integration with external REST APIs. We have encountered such tasks dozens of times and know how to build a module from idea to production—without pain and bike sheds. This saves budget during the maintenance phase.
What technical problems we solve
Chaotic use of hooks without a service layer is the most common issue when auditing third-party modules: N+1 queries in loops, code duplication, inability to reuse logic. The second most frequent is lack of caching or incorrect cache tags, causing pages to load in 5–7 seconds. The third is procedural code in .module files with over a thousand lines, which becomes impossible to maintain.
How to avoid N+1 queries?
Instead of loading each entity one by one in a loop, we use EntityStorageInterface::loadMultiple(): one query to get IDs, a second to load all entities. This turns 20 queries into 2. In our modules, we control this at the service layer.
Why is the DI container important?
Dependency injection (DI) is the Drupal standard. According to Drupal API, each service is defined in services.yml. Thanks to Dependency Injection, code becomes testable and replaceable. If you need to switch caching from database to Redis, change one line in services.yml, not the entire code. DI reduces modification time by 2–3 times, and modules built on services are tested 3 times faster.
How we design the module architecture
Example minimal module structure
For each project, we define a minimal structure. Here is a typical set of files covering 80% of tasks:
web/modules/custom/my_module/ ├── my_module.info.yml ├── my_module.module ├── my_module.services.yml ├── src/ │ ├── Controller/ │ │ └── ArticleController.php │ ├── Service/ │ │ └── ArticleService.php │ ├── Plugin/Block/ │ │ └── RecentPostsBlock.php │ └── EventSubscriber/ │ └── RequestSubscriber.php └── templates/ └── my-module-template.html.twig Example: controller with caching
We implemented an API for outputting articles with pagination and tag-based caching—the client eliminated manual cache invalidation.
// src/Controller/ArticleController.php namespace Drupal\my_module\Controller; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityTypeManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; class ArticleController extends ControllerBase { public function __construct( private readonly EntityTypeManagerInterface $entityTypeManager, ) {} public static function create(ContainerInterface $container): static { return new static( $container->get('entity_type.manager'), ); } public function list(): array { $storage = $this->entityTypeManager->getStorage('node'); $ids = $storage->getQuery() ->condition('type', 'article') ->condition('status', 1) ->sort('created', 'DESC') ->range(0, 20) ->accessCheck(TRUE) ->execute(); $nodes = $storage->loadMultiple($ids); $view_builder = $this->entityTypeManager->getViewBuilder('node'); return [ '#theme' => 'item_list', '#items' => array_map( fn($node) => $view_builder->view($node, 'teaser'), $nodes ), ]; } public function apiList(Request $request): JsonResponse { $page = (int) $request->query->get('page', 0); $limit = min((int) $request->query->get('limit', 10), 100); $storage = $this->entityTypeManager->getStorage('node'); $query = $storage->getQuery() ->condition('type', 'article') ->condition('status', 1) ->sort('created', 'DESC') ->range($page * $limit, $limit) ->accessCheck(TRUE); $ids = $query->execute(); $nodes = $storage->loadMultiple($ids); $data = array_map(function ($node) { return [ 'id' => $node->id(), 'uuid' => $node->uuid(), 'title' => $node->getTitle(), 'created' => $node->getCreatedTime(), 'url' => $node->toUrl()->setAbsolute()->toString(), 'summary' => $node->get('body')->summary, ]; }, $nodes); return new JsonResponse([ 'data' => array_values($data), 'meta' => ['page' => $page, 'limit' => $limit], ]); } } Comparison: simple module vs complex
| Parameter | Simple module | Complex module |
|---|---|---|
| Entities | None | Custom entities + bundle |
| API | None | REST / JSON:API endpoints |
| Caching | Basic | Tags, contexts, dynamic invalidation |
| Events | None | Event subscribers + listeners |
| Timeline | 2–3 days | 8–15 days |
Common mistakes in module development and their solutions
| Mistake | Consequences | Solution |
|---|---|---|
| No service layer | N+1 queries, code duplication | Extract logic into services with DI |
| Ignoring cache tags | Full cache invalidation, slow pages | Assign cache tags per entity |
| Procedural hooks in .module | Hard to maintain and test | Use EventSubscriber for logic |
Additional module components
Blocks with configuration
RecentPosts block with settings: the admin changes the number of posts via the interface without touching code. We use ContainerFactoryPluginInterface to inject services into the plugin.
Event subscribers for custom logic
Note: when you need to react to every request (e.g., check the X-Api-Version header), an event subscriber is more elegant than checks in every controller. Registration via the event_subscriber tag in services.yml.
Hooks and update schemas
We keep procedural hooks only where there is no alternative. For example, hook_node_presave for auto-calculating reading time. For module installation and migrations, we use .install files with update hooks.
Work process and timeline
- Requirements analysis and architecture design — 1–2 days.
- Module implementation — 2 to 15 days.
- Testing (unit + functional) — 1–2 days.
- Deployment and documentation — 1 day.
Final timelines depend on complexity: from 2 days for a basic module to 3 weeks for a comprehensive solution.
What's included in turnkey development
- Module architecture design
- Coding (services, controllers, plugins, hooks, events)
- Caching setup with tags and invalidation
- Unit testing (PHPUnit) and functional tests
- Installation and configuration documentation
- Source code and access handover
- Code warranty up to 3 months and one month of free support
Our advantages
Over 5 years of Drupal development experience, 50+ successful projects. We follow Drupal coding standards and use modern practices—DI container, event architecture, cache tags. Using the DI container reduces modification time by 2–3 times compared to procedural code, and modules built on services are tested 3 times faster. We provide a code warranty of up to 3 months—if errors occur or modifications are needed within the agreed functionality, we fix them for free. Within a month after delivery—free support and consultations.
Contact us for a free assessment of your project. Order a turnkey module development and get a reliable solution without hidden extras. If you need such development, get a consultation on your project today.







