Skip to content

edwtorba/Drupal-9-Module-Development-Third-Edition

 
 

Repository files navigation

Drupal 9 Module Development - Third Edition

Drupal 9 Module Development - Third Edition

This is the code repository for Drupal 9 Module Development - Third Edition, published by Packt.

Get up and running with building powerful Drupal modules and applications

What is this book about?

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.

This book covers the following exciting features:

  • 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

If you feel this book is for you, get your copy today!

https://www.packtpub.com/

Instructions and Navigations

All of the code is organized into folders. For example, Chapter02.

The code will look like the following:

hello_world.hello:
  path: '/hello'
  defaults:
    _controller:  Drupal\hello_world\Controller\HelloWorldController::helloWorld
    _title: 'Our first route'
  requirements:
    _permission: 'access content'

Following is what you need for this book: 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.

With the following software and hardware list you can run all code files present in the book (Chapter 1-18).

Software and Hardware List

Chapter Software required OS required
1-18 Drupal 9 or higher(9.0.2, 9.0.3) Windows, Mac OS X, and Linux (Any)
1-18 MySQL 5.7.8/MariaDB 10.3.7/Percona Server 5.7.8 Windows, Mac OS X, and Linux (Any)
1-18 Apache 2.4.7 or higher, Nginx 1.1 or higher Windows, Mac OS X, and Linux (Any)
1-18 PHP 7.3 (install via composer) Windows, Mac OS X, and Linux (Any)

Setup

To set up a local development environment, perform the following:

  1. Run the following commands:
$ docker-compose up -d
$ docker-compose exec php composer install
$ docker-compose exec php ./vendor/bin/run drupal:site-install
  1. Go to http://localhost:8080 and you have a Drupal site running. To log in, use admin / admin.

Modules

The modules covered in the book are found inside the packt folder in the root of the project. These are duplicated in each chapter and are individually symlinked in the Drupal custom module folder.

By default, when setting up the project, the chapter 2 modules are symlinked. You can change this by creating a local runner.yml file and overriding the chapter value that is used in the symlink (check the default in the runner.yml.dist file).

Once that is done, you can run the following command to symlink the right modules:

$ docker-compose exec php ./vendor/bin/run drupal:module-setup

Mails

All outgoing sent using the native PHP mailer are caught using Mailhog. You can access the emails at http://localhost:8025.

Tests

Run tests as follows:

$ docker-compose exec -u www-data php ./vendor/bin/phpunit

This will run all the tests in the configured packt modules.

Coding standards

To run the coding standards check, use this command:

$ docker-compose exec php ./vendor/bin/run drupal:phpcs

And this command to try to automatically fix coding standards issues that pop up:

$ docker-compose exec php ./vendor/bin/run drupal:phpcbf

Errata

  • Page 43 (Custom submit handler code snippet): 'hello_world_salutation_configuration_form_submit'; should be 'my_module_salutation_configuration_form_submit';
  • Page 147 (code snippet): \Drupal\user\UsedDataInterface should be \Drupal\user\UserDataInterface

Related products

Get to Know the Author

Daniel Sipos is a senior web developer specializing in Drupal. He's been working with Drupal sites since version 6, and started out, like many others, as a site builder. He's a self-taught programmer with many years' experience working professionally on complex Drupal 7 and 8 projects. In his spare time, he runs webomelette.com, a Drupal website where he writes technical articles, tips, and techniques related to Drupal development.

About

Drupal 9 Module Development, published by Packt

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 99.1%
  • Other 0.9%