Drupal Drupal 2 — Questions and Answers
Question 1: Which Drupal hook is used to alter an existing form before it is rendered?
- hook_form_alter() (Correct answer)
- hook_form_submit()
- hook_node_alter()
- hook_preprocess_form()
Correct answer: hook_form_alter()
hook_form_alter() lets modules modify any form by reference before it is displayed to the user.
Question 2: What is the purpose of Drupal's 'cache tags' system?
- To label cached items so they can be invalidated selectively (Correct answer)
- To set expiration times on cache entries
- To encrypt cached data for security
- To compress cached HTML output
Correct answer: To label cached items so they can be invalidated selectively
Cache tags allow granular invalidation — when a node changes, only caches tagged with that node's ID are cleared.
Question 3: In Drupal 9/10, which service handles dependency injection for custom services?
- The Symfony service container (Correct answer)
- The Drupal Registry
- The hook system
- The module handler
Correct answer: The Symfony service container
Drupal 9/10 uses Symfony's service container to manage and inject dependencies into services and plugins.
Question 4: What does the 'drush cr' command do?
- Rebuilds the Drupal cache (Correct answer)
- Creates a new Drupal role
- Runs cron tasks
- Resets the admin password
Correct answer: Rebuilds the Drupal cache
'drush cr' (cache-rebuild) clears and rebuilds all Drupal caches, equivalent to visiting /admin/config/development/performance.
Question 5: Which file in a Drupal theme defines the theme's metadata, regions, and libraries?
- themename.info.yml (Correct answer)
- themename.module
- themename.libraries.yml
- template.php
Correct answer: themename.info.yml
The .info.yml file declares the theme name, core compatibility, regions, and which base theme it extends.
Question 6: What is a 'paragraph' in the context of the Drupal Paragraphs module?
- A reusable content component that can be embedded in entity fields (Correct answer)
- A plain text area field type
- A block that appears in the sidebar
- A Twig template partial
Correct answer: A reusable content component that can be embedded in entity fields
The Paragraphs module provides component-style entities that editors embed in fields to build flexible page layouts.
Question 7: In Drupal, what is the role of the 'update.php' script?
- Runs pending database schema updates after a module upgrade (Correct answer)
- Updates Drupal core files via the browser
- Refreshes all cached configuration
- Synchronizes the config directory with the database
Correct answer: Runs pending database schema updates after a module upgrade
update.php executes hook_update_N() implementations to migrate the database schema when modules are upgraded.
Which Drupal hook is used to alter an existing form before it is rendered?