Skip to main content
Drupal Interview Questions

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.manager

  • database

  • logger.factory

3. How to create a custom module in Drupal 8/9?

Steps:

  1. Create a folder inside /modules/custom/my_module

  2. Add my_module.info.yml

  3. (Optional) Add .module, .routing.yml, .services.yml

  4. Enable 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 BlockBase

  • Use @Block annotation

  • Implement build() method

Blocks are reusable UI components that can be placed via Block Layout.

6. Difference between a node and a block in Drupal?

NodeBlock
Content entityUI component
Stored in databaseRendered output
Has fieldsUsually static/dynamic content
Examples: Article, PageHeader, 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:

  1. Create /themes/custom/my_theme

  2. Add my_theme.info.yml

  3. Add 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 7Drupal 8/9
ProceduralObject-oriented
Hook-heavyServices & events
PHPTemplateTwig
No ComposerComposer-based
Limited APIsModern 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 TagsCache Contexts
Invalidate cacheVary cache
Based on data changeBased on request
Example: node:1Example: 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?

HooksEvent Subscribers
ProceduralObject-oriented
Drupal-specificSymfony-based
Hard to testEasy to test
Older approachModern 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

hook_form_alter()
  • React when an entity is saved

hook_entity_insert()
  • Modify a query

hook_query_alter()
  • Change render output

hook_preprocess_page()
Why Hooks Fit Here
  • Directly tied to Drupal lifecycle

  • Easy to implement

  • No service definitions required

  • Ideal for small, isolated changes

When to Use Event Subscribers in Drupal
Use Event Subscribers When:
  • You need to react to Symfony or system-level events

  • The logic is complex or reusable

  • You want object-oriented, testable code

  • You are building enterprise or API-heavy applications

  • The logic should run before or after requests globally

Common Event Subscriber Use Cases
  • Intercept HTTP requests

  • Modify responses

  • Add custom headers

  • Handle authentication logic

  • Track user behavior

  • Act on kernel-level events

Why Event Subscribers Fit Here
  • Based on Symfony Event Dispatcher

  • Clean separation of concerns

  • Easy to unit test

  • Better for large codebases

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.php overrides

  • Environment-specific config splits

  • Config Ignore / Config Split modules

Example:

  • Dev - enable debug

  • Prod - disable debug