Drupal Interview Preparation Guide
1. Difference between Authentication and Authorization
Authentication verifies who the user is (login using username/password, OAuth, SSO).
Authorization determines what the authenticated user is allowed to do (permissions like “edit content”, “administer users”).
Authentication comes first, authorization comes after.
2. What is a Service Container in Drupal?
The service container in Drupal is a centralized system that manages reusable objects called services (e.g., database, mail manager, entity manager).
It helps:
Avoid tight coupling
Improve testability
Follow dependency injection principles
Example services:
entity_type.managerdatabaselogger.factory
3. How to create a custom module in Drupal 8/9?
Steps:
Create a folder inside
/modules/custom/my_moduleAdd
my_module.info.yml(Optional) Add
.module,.routing.yml,.services.ymlEnable the module using UI or Drush
Example info.yml:
name: My Module
type: module
core_version_requirement: ^8 || ^9 || ^10
package: Custom
4. What are hooks in Drupal?
Hooks are procedural functions that allow modules to alter or extend Drupal’s behavior without modifying core code.
Example:
hook_form_alter()
hook_node_insert()
Hooks are mainly used for:
Altering forms
Reacting to entity events
Modifying data
5. How to create a custom block in Drupal?
Create a Block Plugin:
Extend
BlockBaseUse
@BlockannotationImplement
build()method
Blocks are reusable UI components that can be placed via Block Layout.
6. Difference between a node and a block in Drupal?
| Node | Block |
|---|---|
| Content entity | UI component |
| Stored in database | Rendered output |
| Has fields | Usually static/dynamic content |
| Examples: Article, Page | Header, Sidebar, Footer |
7. How to use Drupal’s Entity API?
Drupal Entity API is used to create, load, update, and delete entities.
Example:
$node = \Drupal::entityTypeManager()
->getStorage('node')
->load($nid);
It provides:
Unified data handling
Strong typing
Field API integration
8. What is a Drupal theme and how to create one?
A Drupal theme controls the presentation layer (HTML, CSS, JS).
Steps:
Create
/themes/custom/my_themeAdd
my_theme.info.ymlAdd Twig templates and libraries
Themes use Twig, not PHP templates.
9. How to implement caching in Drupal?
Drupal supports caching via:
Page cache
Dynamic page cache
Render cache
Block cache
Key cache metadata:
Cache tags
Cache contexts
Cache max-age
Proper caching improves performance significantly.
10. What are Drupal’s configuration management features?
Drupal uses Config Management (CMI) to:
Export configuration to YAML
Import configuration across environments
drush cex
drush cim
Used for:
Site settings
Views
Content types
Roles and permissions
11. How to create and use custom fields in Drupal?
Fields can be created via:
UI (Manage fields)
Code (Field API)
Fields are attached to:
Content types
Entities
Custom entity types
Drupal supports reusable field storage.
12. Difference between Drupal 7 and Drupal 8/9?
| Drupal 7 | Drupal 8/9 |
|---|---|
| Procedural | Object-oriented |
| Hook-heavy | Services & events |
| PHPTemplate | Twig |
| No Composer | Composer-based |
| Limited APIs | Modern Symfony APIs |
13. How to use Views in Drupal?
Views is a query builder UI used to:
List content
Build pages, blocks, feeds
Views supports:
Filters
Sorting
Pagination
Relationships
It eliminates most custom query code.
14. What is the purpose of hook_menu()?
hook_menu() was used in Drupal 7 for:
Defining routes
Menu items
Page callbacks
In Drupal 8+, it is replaced by Routing YAML and Controllers.
15. How to implement multilingual support in Drupal?
Enable modules:
Language
Content Translation
Interface Translation
Drupal supports:
Content translation
Configuration translation
UI translation
Languages can be assigned per entity and field.
16. What are Drupal user roles and permissions?
Roles group permissions
Permissions control access to actions
Example roles:
Anonymous
Authenticated
Administrator
Access control is role-based and granular.
17. How to hide a module from the module listing page though it is enabled?
Add in .info.yml:
hidden: true
This keeps the module enabled but hides it from the UI module list.
18. What is a Design Pattern and which design patterns does Drupal use?
A design pattern is a reusable solution to common software problems.
Drupal uses:
Dependency Injection
Factory Pattern
Singleton (limited)
Observer (Event system)
Plugin pattern
19. Difference between Cache Tags and Cache Contexts?
| Cache Tags | Cache Contexts |
|---|---|
| Invalidate cache | Vary cache |
| Based on data change | Based on request |
Example: node:1 | Example: user, url |
20. What is an Event Subscriber in Drupal?
An Event Subscriber listens to Symfony events and executes logic when the event occurs.
Example events:
Kernel request
Response
Entity events
It replaces many hook use cases.
21. Difference between Event Subscriber and Hooks in Drupal?
| Hooks | Event Subscribers |
|---|---|
| Procedural | Object-oriented |
| Drupal-specific | Symfony-based |
| Hard to test | Easy to test |
| Older approach | Modern approach |
When to Use Hooks in Drupal
Use Hooks When:
You need to alter existing Drupal data or behavior
You are working with forms, entities, or render arrays
The logic is simple and procedural
You want quick integration with Drupal core APIs
Backward compatibility or legacy code is involved
Common Hook Use Cases
Alter a form
React when an entity is saved
Modify a query
Change render output
22. Explain Drupal Behaviors
Drupal Behaviors attach JavaScript functionality after AJAX or page load.
They ensure JS runs:
On initial page load
After AJAX updates
Used instead of document.ready().
23. What is Dependency Injection in Drupal?
Dependency Injection means injecting services instead of calling them statically.
Benefits:
Testability
Loose coupling
Clean architecture
Implemented via constructors.
24. Which DB Engine does Drupal use?
Drupal supports:
MySQL / MariaDB
PostgreSQL
SQLite
It uses Database Abstraction Layer, making DB engine interchangeable.
25. What is SDC in Drupal?
SDC (Single Directory Components) is a Drupal feature that groups:
Twig
CSS
JS
Metadata
Into one component directory, improving frontend architecture.
26. Why do we use annotations in Drupal?
Annotations are used to:
Register plugins
Provide metadata
Example:
Block plugins
Queue workers
Field formatters
They replace manual registration.
27. Why YAML is used instead of TPL files in Drupal?
YAML is used for:
Configuration
Routing
Services
TPL (PHPTemplate) was replaced by Twig, which is safer, cleaner, and more maintainable.
28. How can we defer some configuration to be pushed to respective environments?
By using:
settings.phpoverridesEnvironment-specific config splits
Config Ignore / Config Split modules
Example:
Dev - enable debug
Prod - disable debug