0%

Book Description

Build and extend flexible Drupal sites and applications with this up-to-date, expert guide to Drupal 9 module development

Key Features

  • Explore the essential Drupal 9 APIs for module development
  • Learn how to implement data modeling, caching, architecture, and much more in your Drupal applications
  • Discover what's new in the latest Drupal core releases

Book Description

With its latest release, Drupal 9, the popular open source CMS platform has been updated with new functionalities for building complex Drupal apps with ease. This third edition of the Drupal Module Development guide covers these new Drupal features, helping you to stay on top of code deprecations and the changing architecture with every release.

The book starts by introducing you to the Drupal 9 architecture and its subsystems before showing you how to create your first module with basic functionality. You'll explore the Drupal logging and mailing systems, learn how to output data using the theme layer, and work with menus and links programmatically. Once you've understood the different kinds of data storage, this Drupal guide will demonstrate how to create custom entities and field types and leverage the Database API for lower-level database queries. You'll also learn how to introduce JavaScript into your module, work with various file systems, and ensure that your code works on multilingual sites. Finally, you'll work with Views, create automated tests for your functionality, and write secure code.

By the end of the book, you'll have learned how to develop custom modules that can provide solutions to complex business problems, and who knows, maybe you'll even contribute to the Drupal community!

What you will learn

  • Develop custom Drupal 9 modules for your applications
  • Master different Drupal 9 subsystems and APIs
  • Model, store, manipulate, and process data for effective data management
  • Display data and content in a clean and secure way using the theme system
  • Test your business logic to prevent regression
  • Stay ahead of the curve and write PHP code by implementing best practices

Who this book is for

If you are a Drupal developer looking to learn Drupal 9 to write modules for your sites, this book is for you. Drupal site builders and PHP developers with basic object-oriented programming skills will also find this book helpful. Although not necessary, some Symfony experience will help with understanding concepts easily.

Table of Contents

  1. Drupal 9 Module Development
  2. Third Edition
  3. Why subscribe?
  4. Foreword
  5. Contributors
  6. About the author
  7. About the reviewers
  8. Packt is searching for authors like you
  9. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Conventions used
    6. Get in touch
    7. Reviews
  10. Chapter 1: Developing for Drupal 9
    1. Introducing Drupal (for developers)
    2. How did we get to Drupal 9?
    3. Developing for Drupal
    4. Technologies that drive Drupal
      1. PHP
      2. Databases and MySQL
      3. The web server
      4. Drupal architecture
      5. Drupal's major subsystems
      6. Tools for developing in Drupal
    5. Summary
  11. Chapter 2: Creating Your First Module
    1. Creating a module
      1. Your first hook implementation
      2. Route and controller
      3. Services
    2. Using services in Drupal
      1. Injecting the service into our Controller
      2. Invoked Controllers
    3. The Form API
      1. Altering forms
      2. Custom submit handlers
      3. Rendering forms
      4. Service dependencies
    4. Blocks
      1. Our first block plugin
      2. Block configuration
    5. Working with links
      1. The URL
      2. The link
      3. Which way to link?
    6. Event Dispatcher and redirects
      1. Redirecting from a Controller
      2. Redirecting from a subscriber
      3. Dispatching events
    7. Summary
  12. Chapter 3: Logging and Mailing
    1. Logging
      1. The Drupal logging theory
      2. Our own logger channel
      3. Our own logger
      4. Logging for Hello World
      5. Logging recap
    2. Mail API
      1. The theory behind the Mail API
      2. Implementing hook_mail()
      3. Sending emails
      4. Altering someone else's emails
      5. Custom mail plugins
      6. Mail API recap
    3. Tokens
      1. The Token API
      2. Using tokens
      3. Defining new tokens
      4. Tokens recap
    4. Summary
  13. Chapter 4: Theming
    1. Business logic versus presentation logic
    2. Twig
    3. Theme hooks
      1. Theme hook suggestions
    4. Render arrays
      1. The structure of a render array
      2. The render pipeline
    5. Assets and libraries
      1. Libraries
    6. Common theme hooks
      1. Lists
      2. Links
      3. Tables
    7. Attributes
    8. Layouts
      1. Defining layouts
      2. Rendering a layout
    9. Theming our Hello World module
    10. Summary
  14. Chapter 5: Menus and Menu Links
    1. The menu system
      1. Menus
      2. Menu links
      3. MenuLink trees
    2. Rendering menus
    3. Working with menu links
      1. Defining menu links
      2. Manipulating menu links
    4. Defining local tasks
    5. Defining local actions
    6. Defining contextual links
    7. Summary
  15. Chapter 6: Data Modeling and Storage
    1. Different types of data storage
    2. State API
    3. TempStore
      1. Private TempStore
      2. Shared TempStore
      3. Tempstore recap
    4. UserData API
    5. Configuration API
      1. Introduction
      2. Configuration storage
      3. Configuration recap
    6. Entities
      1. Content versus configuration entity types
      2. Entity type plugins
      3. Fields
      4. Entity types recap
    7. TypedData
      1. Why TypedData?
      2. What is TypedData?
      3. The low-level API
      4. Content entities
      5. TypedData recap
    8. Interacting with the Entity API
      1. Querying entities
      2. Loading entities
      3. Reading entities
      4. Manipulating entities
      5. Creating entities
      6. Rendering content entities
      7. Pseudo-fields
      8. Entity validation
    9. Summary
  16. Chapter 7: Your Own Custom Entity and Plugin Types
    1. Our custom content entity type
      1. Entity updates
      2. Our custom plugin type
      3. Our custom configuration entity type
      4. The Importer plugin
      5. Content entity bundles
    2. Our own Drush command
    3. Summary
  17. Chapter 8: The Database API
    1. The Schema API
    2. Running queries
      1. Select queries
      2. Pagers
      3. Insert queries
      4. Update queries
      5. Delete queries
    3. Transactions
    4. Query alters
    5. Update hooks
    6. Post update hooks
    7. Summary
  18. Chapter 9: Custom Fields
    1. A recap of Field type plugins
    2. Field type
    3. Field widget
    4. Field formatter
    5. Field settings
    6. Using our custom field type as a base field
    7. Summary
  19. Chapter 10: Access Control
    1. Introduction to the Drupal access system
      1. Roles and permissions under the hood
      2. Defining permissions
      3. Checking the user credentials
    2. Route access
      1. Custom route access
      2. Programmatically checking access on routes
      3. Bonus – dynamic route options for access control
      4. CSRF protection on routes
      5. Altering routes
    3. Entity access
      1. Injecting services into Entity handlers
      2. Entity access hooks
      3. Field access
      4. Entity access in routes
      5. Node access grants
    4. Block access
    5. Summary
  20. Chapter 11: Caching
    1. Introduction to caching
    2. Cacheability metadata
      1. Cache tags
      2. Cache contexts
      3. Max-age
      4. Using the cache metadata
    3. Placeholders and lazy building
      1. Lazy builders
    4. Using the Cache API
      1. Creating our own cache bin
    5. Summary
  21. Chapter 12: JavaScript and the Ajax API
    1. JavaScript in Drupal
      1. Drupal behaviors
      2. Drupal settings
    2. The Ajax API
      1. Ajax links
      2. Ajax in forms
    3. The States (Form) system
    4. Summary
  22. Chapter 13: Internationalization and Languages
    1. Introduction to the multilingual ecosystem
      1. Language
      2. Content translation
      3. Configuration translation
      4. Interface translation
    2. Internationalization
    3. Content entities and the Translation API
    4. Summary
  23. Chapter 14: Batches, Queues, and Cron
    1. Batch-powered update hooks
    2. Batch operations
      1. Creating the batch
      2. Batch operations
    3. Cron
    4. Queues
      1. Introduction to the Queue API
      2. Cron-based queues
      3. Processing a queue programmatically
    5. The Lock API
    6. Summary
  24. Chapter 15: Views
    1. Entities in Views
    2. Exposing custom data to Views
      1. Views data
    3. Custom Views field
      1. Field configuration
    4. Custom Views filter
    5. Custom Views argument
    6. Views theming
    7. Views hooks
    8. Summary
  25. Chapter 16: Working with Files and Images
    1. The filesystem
    2. Stream wrappers
    3. Managed versus unmanaged files
    4. Using the File and Image fields
    5. Working with managed files
      1. Attaching managed files to entities
      2. Helpful functions for dealing with managed files
      3. Managed file uploads
    6. Our own stream wrapper
    7. Working with unmanaged files
    8. Private filesystem
    9. Images
      1. Image toolkits
      2. Image styles
      3. Rendering images
    10. Summary
  26. Chapter 17: Automated Testing
    1. Testing methodologies in Drupal 9
    2. PHPUnit
    3. Registering tests
    4. Unit tests
      1. Mocked dependencies
    5. Kernel tests
      1. TeamCleaner test
      2. CsvImporter test
    6. Functional tests
      1. Configuration for Functional tests
      2. Hello World page test
      3. Hello World form test
    7. Functional JavaScript tests
      1. Time test
      2. CsvImporter test
    8. Summary
  27. Chapter 18: Drupal Security
    1. Cross-Site Scripting (XSS)
      1. Sanitization methods in Drupal 9
      2. Double escaping
    2. SQL Injection
    3. Cross-Site Request Forgery (CSRF)
    4. Summary
  28. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
3.81.13.254