Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Drupal 10 Masterclass

You're reading from  Drupal 10 Masterclass

Product type Book
Published in Dec 2023
Publisher Packt
ISBN-13 9781837633104
Pages 310 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Adam Bergstein Adam Bergstein
Profile icon Adam Bergstein

Table of Contents (31) Chapters

Preface 1. Part 1:Foundational Concepts
2. Chapter 1: What is Drupal? 3. Chapter 2: Drupal Core, Modules, and Themes 4. Chapter 3: Infrastructure and Overview of Technical Architecture 5. Chapter 4: Drupal Community 6. Chapter 5: What’s New in Drupal 10 7. Part 2:Setting up - Installing and Maintaining
8. Chapter 6: Bootstrapping, Installing, and Configuring a New Drupal Project 9. Chapter 7: Maintaining Drupal 10. Part 3:Building - Features and Configuration
11. Chapter 8: Content Structures and Multilingual 12. Chapter 9: Users, Roles, and Permissions 13. Chapter 10: Drupal Views and Display Modes 14. Chapter 11: Files, Images, and Media 15. Chapter 12: Search 16. Chapter 13: Contact Forms 17. Part 4:Using - Content Management
18. Chapter 14: Basic Content Authoring Experience 19. Chapter 15: Visual Content Management 20. Chapter 16: Content Workflows 21. Part 5:Advanced Topics
22. Chapter 17: Git, Drush, Composer, and DevOps 23. Chapter 18: Module Development 24. Chapter 19: Theme Development 25. Chapter 20: Delivering Drupal Content through APIs 26. Chapter 21: Migrating Content into Drupal 27. Chapter 22: Multisite Management 28. Index 29. Other Books You May Enjoy Appendix A - Drupal Terminology

Working with JS

Much like CSS, for JS to be loaded, the script needs to be referenced by a library, and then the library needs to be loaded by the theme. The JS can be placed in any directory but is typically placed in the themename/js directory.

Drupal behaviors

Drupal behaviors is the term for the JavaScript API that allows JS to process elements that are injected via AJAX.

It usually runs multiple times when a page is loaded. It’ll run first and pass in the document as context. The subsequent times it loads it will then pass in the AJAX element as context:

((Drupal) => {
  Drupal.behaviors.myBehavior = {
    attach(context) {
      context.querySelector('.my-element')?.addClass('is-processed');
    },
  };
})(Drupal);

In the preceding example, we create a behavior called myBehavior. We add this to the Drupal.behaviors array that Drupal runs whenever...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}