Drupal 7 Hooks vs. Drupal 8 Plugins

This article is part of an archive of articles that were formerly on the web site of Poplar ProductivityWare LLC, Jennifer's freelance software development business (which closed for business in April 2022).
Author: Jennifer Hodgdon
Date Written: 7 October, 2013
Type: Presentation
Subject: Drupal

On October 6, 2013, I gave a talk at the Pacific Northwest Drupal Summit in Vancouver BC, entitled "Paradigm Shift: Drupal 7 Hooks to Drupal 8 Plugins". A PDF of the talk slides is attached. The description of the talk is:

Modules in Drupal are meant to interact with, extend, or alter the behavior of Drupal Core or other modules. In Drupal 7 and previous versions of Drupal, the basic mechanism for doing this was implementing a hook: writing a function that provides information or alters behavior in a controlled way. Drupal 8 still has some hooks, but many interactions and alterations that in previous versions of Drupal would be accomplished by implementing hooks have been replaced by a plugin mechanism, which involves making a PHP class to define the desired behavior.

This talk will lead you through the paradigm shift from hooks to plugins. Using one or more examples, we'll see how to implement the same behavioral change using Drupal 7 hooks and Drupal 8 plugins, and learn about PSR-0, namespaces, and plugin annotation along the way.