Acquia Certified Drupal 10 Backend Specialist
Self Evaluation Answers
Answer Key
1. What is the primary difference between entities and configuration entities in Drupal?
Answer: C. Entities represent content and users, while configuration entities store settings and configurations.
Explanation: In Drupal, entities are used to represent and manage data such as content (nodes), users, and taxonomy terms. Configuration entities, on the other hand, are used to store settings and configurations that define how the site behaves.
Reference: Understanding Drupal: Concept: Types of Data
2. How does the Typed Data API contribute to Drupal’s data handling?
Answer: A. It provides a type-safe structure for working with data in entities and fields.
Explanation: The Typed Data API in Drupal offers a consistent and type-safe way to interact with data, ensuring that data types are validated and handled appropriately across entities and fields.
Reference: Typed Data API Overview
3. Which Drupal API is primarily responsible for defining and managing entity types?
Answer: C. Entity API
Explanation: The Entity API in Drupal is responsible for defining and managing entity types, providing a unified way to handle different kinds of data entities within the system.
Reference: Introduction to Entity API in Drupal 8
4. What is the required file to define a custom Drupal module?
Answer: C.
{module_name}.info.yml
Explanation: To define a custom module in Drupal, you need to create an.info.yml
file named after your module (e.g.,my_module.info.yml
). This file provides essential metadata about the module, such as its name, type, description, and dependencies.
Reference: Creating Modules
5. Which of the following statements about services in Drupal is TRUE?
Answer: B. Services are registered in
{module_name}.services.yml
and instantiated by the container.
Explanation: In Drupal, services are defined in a module's.services.yml
file. These services are then managed by Drupal's service container, which handles their instantiation and dependency injection.
Reference: Services and Dependency Injection in Drupal
6. What is the purpose of the hook_help()
function in a custom module?
Answer: A. To provide user guidance and documentation for the module.
Explanation: Thehook_help()
function allows a module to define help text that can be displayed to users, offering guidance and documentation about the module's functionality.
Reference: hook_help() Documentation
7. Which service is used to load an entity in Drupal?
Answer: C.
\Drupal::entityTypeManager()->getStorage()
Explanation: To load an entity in Drupal, you use theentityTypeManager
service to get the appropriate storage handler for the entity type, and then use it to load the entity.
Reference: Working with the Entity API
8. What is the correct way to programmatically create a new node entity?
Answer: B. Using
Node::create()
andsave()
Explanation: To programmatically create a new node in Drupal, you can use theNode::create()
method to instantiate a new node object, set its properties, and then call thesave()
method to persist it.
Reference: Programmatically Creating Nodes
9. Which API is primarily responsible for defining and managing plugin-based extensibility in Drupal?
Answer: B. Plugin API
Explanation: The Plugin API in Drupal provides a flexible system for managing small pieces of functionality, allowing for easy extension and customization.
Reference: Plugin API Overview
10. How do you define a custom plugin type in Drupal?
Answer: A. By creating a new class with an annotation in the
src/Plugin
directory.
Explanation: To define a custom plugin type in Drupal, you create a new PHP class in thesrc/Plugin
directory of your module, using annotations to define the plugin's metadata.
Reference: Creating a Custom Plugin Type
11. Which of the following statements about Drupal’s Database API is TRUE?
Answer: B. The Database API provides an abstraction layer to prevent SQL injection and ensure compatibility.
Explanation: Drupal's Database API offers an abstraction layer that helps prevent SQL injection attacks and ensures compatibility across different database systems.
Reference: Database API Overview
12. What is the correct way to retrieve a configuration value in Drupal?
Answer: B.
\Drupal::config('my_module.settings')->get('my_value')
Explanation: To retrieve a configuration value in Drupal, you use theconfig
service to access the desired configuration object and then call theget()
method with the specific key.
Reference: Configuration API Overview
13. Which of the following is a valid use case for the State API?
Answer: A. Storing temporary runtime data, such as the last cron run time.
Explanation: The State API is intended for storing temporary, environment-specific data that does not need to be deployed across environments, such as the last time cron was run.
Reference: State API
14. How does Drupal's Cache API improve performance?
Answer: B. By using cache bins to store rendered HTML, database queries, and computed values.
Explanation: Drupal's Cache API enhances performance by storing frequently used data, such as rendered HTML and computed values, in cache bins, reducing the need for repeated processing.
Reference: Cache API
15. Which of the following is a best practice for securing user-submitted data in Drupal?
Answer: C. Use the
Html::escape()
function to sanitize user-generated content before rendering.
Explanation: To prevent cross-site scripting (XSS) attacks, it's essential to sanitize user-generated content before rendering it. TheHtml::escape()
function is commonly used for this purpose in Drupal.
Reference: Writing secure code for Drupal
16. What is the correct permissions for index.php?
Answer: A. -rw-r----- Explanation: The "index.php" file (representative of all code files) can be edited by "deploy" and can be read by the www-data group (we assume the www-data user is in the www-data group). No other users can read that file. This is a fairly secure method of configuring your site. You generally don't want random users who have the ability to read files on your server to see inside those files, hence the last three permissions are --- instead of r-x.
Reference: Securing file permissions and ownership
17. What is the correct way to write a message to Drupal’s log file?
Answer: A.
\Drupal::logger('mymodule')->notice('Log message here');
Explanation: To write a message to Drupal's log, you can use thelogger
service, specifying the channel (e.g., 'mymodule') and the log level (e.g.,notice
), followed by the message.
Reference: Logging API
18. Which service provides a structured way to output debugging information in Drupal?
Answer: C.
\Drupal::service('devel.dumper')
Explanation: The Devel module provides adumper
service that offers structured and readable output for debugging purposes.
Reference: Devel Module
19. What is the purpose of Kernel tests in Drupal?
Answer: B. To test integration between Drupal’s backend and its database.
Explanation: Kernel tests in Drupal are designed to test the integration of various subsystems, including interactions with the database, without bootstrapping the entire Drupal environment.
Reference: Running PHPUnit tests
20. What command is used to run PHPUnit tests for a custom module?
Answer: D.
./vendor/bin/phpunit --testsuite=custom_module
Explanation: To run PHPUnit tests for a custom module, you can use the PHPUnit executable located in thevendor/bin
directory, specifying the test suite corresponding to your module.
Reference: Running PHPUnit Tests
These explanations and references should help validate the correct answers and provide further insight into Drupal's backend development practices.