hooks

Why Drupal module developers should be excited about object-oriented hooks

Published October 29, 2024
It's not super-often that a Drupal core change record stops me in my tracks, but recently, one did exactly that. With so much of Drupal core written using modern, object-oriented PHP, there was still one place where we needed to use plain-old PHP functions: hook implementations. Drupal hooks have been with us since before I started with Drupal (over 18 years ago,) and I had long hoped that with the advent of "modern" Drupal (Drupal 8+,) eventually hooks would be converted over to Symfony events. Much to my surprise, a recent change record for Drupal 11.x-dev (to be included in

I need to change the number of items returned by a view, based on the theme!

Published July 16, 2010

A friend recently came to me with the following question:

I have a site that has a mode optimized for low-bandwidth use. Can I change the number of rows returned by a view based on the theme?

The Views 2 API has a function called hook_views_query_alter() which allows you to modify the View object before it pulls the results from the database.

In order to use views hooks, you must create a module that registers itself as using the Views API: