First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.
Continue in the practice tool above to load more questions, 50 at a time.
Question 1Drupal 10 back end development (site building, module development, theming, performance, security)
In a Drupal 10 module, which file is required for Drupal to recognize and register the module?
- my_module.info.yml Correct answer.
- my_module.module
- my_module.routing.yml
- my_module.services.yml
Explanation
Drupal discovers modules by scanning for a .info.yml file, which contains the module's name, type, core_version_requirement, and other metadata. Without it the module is not listed or enabled. The .module, routing, and services files are optional and only loaded after the module is registered.
Question 2Drupal 10 back end development (site building, module development, theming, performance, security)
Which YAML key in a *.services.yml file makes a service available to other modules through the service container?
- services Correct answer.
- arguments
- tags
- public
Explanation
Services are declared under the top-level 'services' key in a *.services.yml file, each with a class and optional arguments, tags, and visibility. The other keys are properties of an individual service definition rather than the container declaration itself.
Question 3Drupal 10 back end development (site building, module development, theming, performance, security)
Which hook is invoked when a module is first enabled, making it the correct place to create configuration or schema?
- hook_enable()
- hook_entity_insert()
- hook_install() Correct answer.
- hook_modules_installed()
Explanation
hook_install() runs once when the module is installed and is the standard place to create default configuration and database schema. hook_enable() fires on every enable, including re-enables, so it is not suitable for one-time setup.
Question 4Drupal 10 back end development (site building, module development, theming, performance, security)
A developer needs to alter a form built by another module without modifying that module's code. Which hook should be implemented?
- hook_entity_presave()
- hook_preprocess_HOOK()
- hook_page_attachments()
- hook_form_alter() Correct answer.
Explanation
hook_form_alter() lets a module modify any form's structure before it is rendered or processed, keyed by form ID. This is the canonical extension point for changing another module's form.
Question 5Drupal 10 back end development (site building, module development, theming, performance, security)
In a Drupal 10 render array, which property controls whether a child element is rendered before or after its siblings?
- #cache
- #weight Correct answer.
- #access
- #attached
Explanation
The #weight property determines ordering of elements within a render array; lower weights render first. It is commonly used in form alters and preprocess functions to reorder output.
Question 6Drupal 10 back end development (site building, module development, theming, performance, security)
Which Twig function outputs a rendered child render array inside a template?
- {{ link() }}
- {{ attach_library() }}
- {{ drupal_entity() }}
- {{ render_var() }} Correct answer.
Explanation
The render_var() function (or the render filter) renders a render array into markup within Twig. It is used when passing structured render arrays to templates.
Question 7Drupal 10 back end development (site building, module development, theming, performance, security)
Which cache context should be used so that a block's cached output varies per logged-in user's roles?
- url
- languages
- user.roles Correct answer.
- user
Explanation
The user.roles cache context makes cached output vary by the set of roles the current user holds. The plain 'user' context varies per individual user, which is broader than needed for role-based output.
Question 8Drupal 10 back end development (site building, module development, theming, performance, security)
Which permission is required for a user to bypass node access checks across all content?
- view own unpublished content
- administer nodes
- bypass node access Correct answer.
- access content overview
Explanation
The 'bypass node access' permission grants a user full access to all nodes regardless of grants or published status. It is distinct from 'administer nodes', which governs node administration tasks.
Question 9Drupal 10 back end development (site building, module development, theming, performance, security)
A developer wants to define a custom route at /my-module/report handled by a controller method. Which file must contain the route definition?
- my_module.links.menu.yml
- my_module.permissions.yml
- my_module.routing.yml Correct answer.
- my_module.info.yml
Explanation
Route definitions belong in a *.routing.yml file, where each route specifies its path, defaults (including _controller or _form), and requirements. Menu links and permissions are declared in separate YAML files.
Question 10Drupal 10 back end development (site building, module development, theming, performance, security)
Which annotation on a plugin class identifies it as a Block plugin in Drupal 10?
- @Block Correct answer.
- @ConfigEntityType
- @EntityType
- @Plugin
Explanation
Block plugins use the @Block annotation (or the Block attribute in newer code) placed in the class docblock, providing an id, admin_label, and category. Other annotations correspond to different plugin or entity types.
Question 11Drupal 10 back end development (site building, module development, theming, performance, security)
How does a module declare a service that implements a tagged plugin manager collector so it can alter plugin definitions?
- Add the service with the tag service_collector. Correct answer.
- Add a *.services.yml entry under the parameters key.
- Register an event subscriber with the kernel.request tag.
- Implement hook_plugin_alter() in the .module file.
Explanation
A plugin definition alterer is registered as a service tagged with service_collector, referencing the plugin manager service it targets. The collector then calls the alterer's alter() method for each definition.
Question 12Drupal 10 back end development (site building, module development, theming, performance, security)
Which method on an entity storage handler loads a single entity by its ID?
- create()
- load() Correct answer.
- loadByProperties()
- loadMultiple()
Explanation
The load() method on an entity storage handler retrieves one entity by its identifier, returning NULL if not found. loadMultiple() takes an array of IDs and loadByProperties() queries by field values.
Question 13Drupal 10 back end development (site building, module development, theming, performance, security)
A developer needs to modify a field value before an entity is saved programmatically. Which hook is most appropriate?
- hook_entity_presave() Correct answer.
- hook_entity_load()
- hook_entity_view()
- hook_entity_insert()
Explanation
hook_entity_presave() fires just before an entity is saved, allowing field values to be adjusted before persistence. The insert hook fires after a new entity is saved, too late to change stored values.
Question 14Drupal 10 back end development (site building, module development, theming, performance, security)
Which construct should a controller return when it needs to render a themed render array with cache metadata?
- A JsonResponse with the markup.
- A render array. Correct answer.
- A plain string of HTML.
- A Symfony Response with raw markup.
Explanation
Returning a render array lets Drupal render it through the theme system and collect cacheability metadata such as tags, contexts, and max-age. Returning raw strings or Symfony responses bypasses that pipeline.
Question 15Drupal 10 back end development (site building, module development, theming, performance, security)
Which cache tag should be invalidated when a specific node is updated so that pages rendering it are refreshed?
- node:5 Correct answer.
- user:5
- config:node.type.article
- node_list
Explanation
Entity cache tags follow the pattern entity_type:id, so node:5 identifies a single node and is invalidated when that node changes. The node_list tag applies to listings of nodes rather than one entity.
Question 16Drupal 10 back end development (site building, module development, theming, performance, security)
In a preprocess function, which variable gives access to the theme hook name being processed when using a generic hook_preprocess() implementation?
- $variables['theme_hook'] Correct answer.
- $variables['#cache']
- $variables['attributes']
- $variables['elements']
Explanation
A generic hook_preprocess() receives the hook name in $variables['theme_hook'] (also available as $hook), allowing one function to handle multiple hooks. The elements key holds the source render array.
Question 17Drupal 10 back end development (site building, module development, theming, performance, security)
Which Twig filter should be used to render a translatable string with a placeholder in a template?
- |t Correct answer.
- |escape
- |raw
- |safe_join
Explanation
The |t filter passes a string through Drupal's translation system and supports placeholders, producing a translated, sanitized result. It is the standard way to translate literal strings in Twig.
Question 18Drupal 10 back end development (site building, module development, theming, performance, security)
Which mechanism lets a module define a new configuration schema so that its settings are translatable and validated?
- A *.permissions.yml entry.
- A hook_schema() implementation.
- A config/schema/*.schema.yml file. Correct answer.
- A *.routing.yml entry.
Explanation
Configuration schema is declared in config/schema/*.schema.yml files, which describe the structure and types of configuration. Schema enables validation, translation of config, and typed config handling.
Question 19Drupal 10 back end development (site building, module development, theming, performance, security)
A developer must run an update to modify existing configuration when upgrading a module. Which hook should contain that logic?
- hook_install()
- hook_requirements()
- hook_post_update_NAME()
- hook_update_N() Correct answer.
Explanation
hook_update_N() functions run during database updates via update.php or drush updb and are the standard place to alter existing configuration or schema. They run once per numbered update.
Question 20Drupal 10 back end development (site building, module development, theming, performance, security)
Which service should be used to build and execute an entity query that returns node IDs matching a condition?
- entity.query Correct answer.
- entity_type.manager
- path.validator
- database
Explanation
The entity.query service (EntityQuery) builds structured queries against entity fields and returns entity IDs, respecting access where configured. It is preferred over raw database queries for entity data.
Question 21Drupal 10 back end development (site building, module development, theming, performance, security)
A block's output depends on the current request's query string. Which cache context is required to avoid serving stale cached output?
- route
- theme
- session
- url.query_args Correct answer.
Explanation
The url.query_args cache context makes cached output vary by query string parameters. Without it, a cached response could be reused across different query strings.
Question 22Drupal 10 back end development (site building, module development, theming, performance, security)
Which approach correctly declares a custom access check for a route using a service?
- Add a permission string to the route's requirements key.
- Reference a service method via the _custom_access route requirement. Correct answer.
- Set _access to TRUE and validate inside the controller.
- Implement hook_route_access() in the .module file.
Explanation
The _custom_access route requirement points to a callable, typically a service method, that returns an AccessResultInterface. This integrates with Drupal's access system and caching.
Question 23Drupal 10 back end development (site building, module development, theming, performance, security)
A module needs to react to a custom event dispatched by another module. What must the subscribing module register?
- An entry in the *.routing.yml file.
- A plugin with the @EventListener annotation.
- A service tagged event_subscriber. Correct answer.
- A service tagged service_collector.
Explanation
Event subscribers are services tagged event_subscriber that implement EventSubscriberInterface, mapping events to handler methods. The dispatcher then invokes the handler when the event fires.
Question 24Drupal 10 back end development (site building, module development, theming, performance, security)
When defining a config entity type, which annotation key specifies the class used to list entities in the admin UI?
- admin_ui
- config_prefix
- list_builder Correct answer.
- handlers
Explanation
Config (and content) entity types declare handlers under the handlers key, and the list_builder key names the class that builds the admin listing. The list builder controls columns and operations shown.
Question 25Drupal 10 back end development (site building, module development, theming, performance, security)
A developer wants a computed field value available on an entity without storing it in the database. Which API supports this?
- A config entity field.
- A computed field item list class. Correct answer.
- A bundle field added via the UI.
- A base field with a storage definition.
Explanation
Computed fields use a field item list class implementing ComputedItemListTrait to calculate values on access without persistence. They are declared in the entity's baseFieldDefinitions with a computed class.
Question 26Drupal 10 back end development (site building, module development, theming, performance, security)
In Drupal 10, which file in a custom module declares its routes and their requirements?
- routing.yml Correct answer.
- services.yml
- permissions.yml
- links.menu.yml
Explanation
Route definitions, including path, defaults, and requirements, belong in a module's routing.yml file, which is compiled into the router. Other YAML files serve different purposes such as service wiring, menu links, or permission definitions.
Question 27Drupal 10 back end development (site building, module development, theming, performance, security)
Which YAML file must a module provide so that its hook implementations are discovered in Drupal 10?
- my_module.module Correct answer.
- my_module.info.yml
- my_module.libraries.yml
- my_module.services.yml
Explanation
Procedural hook implementations live in the .module file, which Drupal includes for enabled modules. The .info.yml describes the extension, services.yml wires services, and libraries.yml declares asset libraries.
Question 28Drupal 10 back end development (site building, module development, theming, performance, security)
Which annotation property on a @Block plugin makes the block available under a specific admin category in the block layout UI?
- admin_label
- derivative
- category Correct answer.
- context_definitions
Explanation
The category annotation groups block plugins in the block placement UI. admin_label changes the displayed label, derivatives define dynamic variants, and context_definitions declare required contexts.
Question 29Drupal 10 back end development (site building, module development, theming, performance, security)
Which function should a module use to retrieve a service from the container inside a procedural hook where injection is not possible?
- Drupal::service() Correct answer.
- Container::resolve()
- service_container()
- PluginManager::get()
Explanation
Drupal::service() is the static accessor for the global container and is acceptable in procedural code. Classes should prefer constructor injection of services instead.
Question 30Drupal 10 back end development (site building, module development, theming, performance, security)
Which Twig tag is used to output a value escaped for HTML by default in a Drupal template?
- {{ value }} Correct answer.
- {% set value %}
- {# value #}
- {% print value %}
Explanation
The double-brace syntax outputs a variable, and Drupal's Twig environment autoescapes it for HTML context. The other constructs are comments, assignments, or invalid tags.
Question 31Drupal 10 back end development (site building, module development, theming, performance, security)
Which base theme class in Drupal 10 provides the default Stable-based markup and is recommended for custom subthemes?
- Stable9 Correct answer.
- Classy
- Olivero
- Bartik
Explanation
Stable9 is the Stable-based base theme shipped with Drupal 10 and is the recommended starting point for custom subthemes. Classy was removed from core in Drupal 10 and moved to contrib.
Question 32Drupal 10 back end development (site building, module development, theming, performance, security)
Which permission grants a role the ability to administer modules and configuration on the site?
- access administration pages
- administer software updates
- administer modules
- administer site configuration Correct answer.
Explanation
The administer site configuration permission is a broad administrative permission covering configuration forms. The other permissions are narrower or cover different administrative tasks.
Question 33Drupal 10 back end development (site building, module development, theming, performance, security)
Which database API class should be used to build a SELECT query in a module while remaining portable across database drivers?
- PDOStatement
- SelectQuery
- Drupal\Core\Database\Query\Select Correct answer.
- Connection::queryDirect()
Explanation
The Drupal\Core\Database\Query\Select class is the database-agnostic query builder for SELECT statements. Using raw PDO or driver-specific SQL reduces portability.
Question 34Drupal 10 back end development (site building, module development, theming, performance, security)
A module needs to alter the output of a form built by another module. Which hook should it implement?
- hook_form_alter() Correct answer.
- hook_theme()
- hook_entity_update()
- hook_preprocess_HOOK()
Explanation
hook_form_alter() lets a module modify any form's structure before rendering. The other hooks target entity saves, template preprocessing, or theme registration.
Question 35Drupal 10 back end development (site building, module development, theming, performance, security)
A developer wants a custom controller method to be reachable only by users with a specific permission. Where should that requirement be declared?
- In the module's permissions.yml file
- In the route's requirements key in routing.yml Correct answer.
- In the module's services.yml file
- In the controller method body using a conditional check
Explanation
Route access requirements such as _permission are declared under the requirements key in routing.yml so the access system enforces them before the controller runs. permissions.yml only defines permission metadata.
Question 36Drupal 10 back end development (site building, module development, theming, performance, security)
Which cache context ensures a render array varies based on the URL query string parameters?
- request_format
- session
- url.query_args Correct answer.
- url.path
Explanation
The url.query_args cache context varies cached output by the request's query string. url.path varies by path, request_format by response format, and session by session data.
Question 37Drupal 10 back end development (site building, module development, theming, performance, security)
A module defines a new service and wants it available to other modules via the container. Which file declares the service?
- my_module.routing.yml
- my_module.links.yml
- my_module.services.yml Correct answer.
- my_module.info.yml
Explanation
Services, their classes, and their arguments are declared in a module's services.yml, which is loaded into the service container. The other files handle metadata, routes, or links.
Question 38Drupal 10 back end development (site building, module development, theming, performance, security)
Which hook should a module implement to add a new theme hook and template suggestion for its own component?
- hook_theme() Correct answer.
- hook_entity_view_alter()
- hook_library_info_alter()
- hook_page_attachments()
Explanation
hook_theme() registers theme hooks with their variables and template or render element callbacks. The other hooks alter libraries, page attachments, or rendered entities.
Question 39Drupal 10 back end development (site building, module development, theming, performance, security)
A developer needs to store per-user preferences in a way that is cached and cleared when the user is updated. Which API is appropriate?
- The key/value store with the user's ID as part of the key
- The state API
- The user data service Correct answer.
- The private tempstore
Explanation
The user data service stores arbitrary data keyed to a user account and is cleared automatically when the user is deleted, making it suitable for per-user preferences. The state API and key/value stores are not user-scoped.
Question 40Drupal 10 back end development (site building, module development, theming, performance, security)
Which construct allows a module to modify a plugin definition provided by another module without editing that module's code?
- A plugin manager decorator tagged as a definition alterer Correct answer.
- A service provider
- A hook_entity_presave() implementation
- A route subscriber
Explanation
Plugin definition alterers are services tagged appropriately that receive all definitions and can modify them. Route subscribers and service providers affect routing or container compilation, not plugin definitions.
Question 41Drupal 10 back end development (site building, module development, theming, performance, security)
A developer wants to add a validation constraint to a custom field type so values are checked on entity save. Which mechanism should be used?
- hook_form_alter()
- Annotation-based constraints on the field item class Correct answer.
- hook_entity_presave()
- A custom database index
Explanation
Constraints declared via annotations on the typed data class are enforced by the validation system whenever the entity is validated. Hooks and form alters do not integrate with the typed data validation pipeline.
Question 42Drupal 10 back end development (site building, module development, theming, performance, security)
Which class should a module extend to subscribe to events dispatched by the Symfony event dispatcher in Drupal?
- Drupal\Core\EventSubscriber
- EventSubscriberBase
- Symfony\Component\EventDispatcher\EventSubscriberInterface Correct answer.
- HookEventSubscriber
Explanation
Event subscribers implement Symfony\Component\EventDispatcher\EventSubscriberInterface and return an event-to-method map from getSubscribedEvents(). The service is then tagged as an event subscriber.
Question 43Drupal 10 back end development (site building, module development, theming, performance, security)
A module needs to expose a new permission that controls access to its administration page. Where is the permission defined?
- In the module's .info.yml
- In permissions.yml Correct answer.
- In routing.yml under requirements
- In services.yml
Explanation
Permissions are declared in permissions.yml, which the permission system reads to build the permission list. Routes then reference the permission machine name in their requirements.
Question 44Drupal 10 back end development (site building, module development, theming, performance, security)
Which API allows a module to define a field whose value is calculated at runtime rather than stored in a database column?
- The key/value store
- The state API
- The configuration API
- The entity field API with a computed field item list class Correct answer.
Explanation
Computed fields are implemented as field item list classes that calculate values on access, integrated into the entity field API. Storage APIs like key/value or state do not integrate with entity rendering.
Question 45Drupal 10 back end development (site building, module development, theming, performance, security)
A developer must ensure that a custom block's cached output is invalidated when any node of a specific bundle changes. Which cache tag strategy is correct?
- Add a cache tag for the specific bundle's list Correct answer.
- Add the node_list cache tag
- Add the config cache tag
- Add the user cache tag
Explanation
Cache tags for entity lists include bundle-specific tags, so adding the bundle list tag invalidates the block when nodes of that bundle change. The node_list tag is broader and invalidates on any node change.
Question 46Drupal 10 back end development (site building, module development, theming, performance, security)
Which approach correctly registers a service as a route access checker for a custom access requirement?
- Declare the class in permissions.yml
- Implement hook_route_alter() in the .module file
- Tag the service with access_check and reference its ID as _custom_access in the route requirements Correct answer.
- Add the class name to the route's defaults key
Explanation
Access check services are tagged access_check and referenced by service ID in route requirements with an underscore prefix. The access manager resolves the service and calls its access() method.
Question 47Drupal 10 back end development (site building, module development, theming, performance, security)
A module needs to run a database update to modify existing configuration when upgrading. Which hook should contain the update logic?
- hook_install()
- hook_schema()
- hook_update_N() Correct answer.
- hook_post_update_NAME()
Explanation
hook_update_N() functions run during database updates and are the standard place to modify existing configuration or schema. hook_install() only runs on first install, and hook_post_update_NAME() runs after all updates.
Question 48Drupal 10 back end development (site building, module development, theming, performance, security)
A developer wants a module to react to an entity being deleted and clean up related custom data. Which hook should be implemented?
- hook_entity_delete() Correct answer.
- hook_entity_presave()
- hook_entity_view()
- hook_entity_access()
Explanation
hook_entity_delete() fires after an entity is deleted, making it suitable for cleanup of related data. The other hooks run before saves, during rendering, or during access checks.
Question 49Drupal 10 back end development (site building, module development, theming, performance, security)
Which technique best improves performance when a module repeatedly loads the same configuration object across a request?
- Clearing the cache on every request
- Loading the configuration from the database directly each time
- Calling getEditableConfigNames() on each use
- Requesting the immutable config factory once and reusing the object Correct answer.
Explanation
Configuration objects are cached by the config factory, and reusing a single immutable config object avoids repeated factory lookups and object construction. Direct database queries bypass caching and are slower.
Question 50Drupal 10 back end development (site building, module development, theming, performance, security)
A developer needs to render a list of entities in a controller with correct cache metadata. Which approach is recommended?
- Return a Response with manually concatenated HTML
- Use drupal_set_message() to output the list
- Return a plain string of concatenated HTML
- Return a render array with #theme and attach cache tags from the entity list Correct answer.
Explanation
Returning a render array lets Drupal apply the theme layer and bubble cache metadata from the entities. Manually building HTML bypasses caching and escaping.