Refactor to #[Hook]

Session Room
Room 2 (Indigital)
Time Slot
Duration
40 min
Speaker(s)
Session track
Coding & Site Building
Experience level
Beginner

Some Hooks became plugins or event subscribers in Drupal 8.
But now it is again to time to refactor. The vast majority of procedural hooks need to be transformed to object oriented hooks.

Prerequisite

No special knowledge is required.

Outline

Code for Drupal 11.1 looks almost like magic again for someone who was used to the magic naming that kept working the same way even in Drupal 11.0.
Hook_block_info has become a plugin a long time ago, and recently plugins changed to use php annotations.
But the big change that happened in Drupal 11.1 is that most of the hooks can now be methods on classes. This allows for better code organisation and better testing because one can use dependency injection.
We will showcase and demo that implementing hooks the new way is just as easy.
And even refactoring everything is nothing to be afraid of.
Everyone should know about #[Hook]

Learning Objectives

You will learn how easy it is to adapt your code to the object oriented way of defining hooks and see that you can test your code much better.
You will also learn about the tools that make your job refactoring much easier.

Educational Track - Drupal in a Day Sponsors

Social Night Sponsors

In-Kind Sponsors

Media Partner Sponsors