php

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

How best to handle "Unsafe usage of new static()" PHPStan errors

Published December 13, 2023
As a Drupal module developer, if you're as big of a fan of PHPStan as I am, then you'll no doubt have run across the Unsafe usage of new static() error that PHPStan throws when analyzing code at level 0. In this article I will describe what causes this error and provide four possible solutions, weighing the pros and cons of each.

Solving a local "502 Bad Gateway" Drupal issue

Published July 17, 2023
I learned a valuable lesson last week. First, some context. One of DrupalEasy's clients is a large international industry association that is currently running a large Drupal 9 site with about a dozen custom modules and well over 150 contributed modules. We were brought onto the project a couple of years ago to do some custom module development, but until recently weren't all that involved in the overall site maintenance and development. As part of a recent task we've been working on, I stumbled on an issue that was occurring only on my local, and not in a way that

Long-form Professional Module Development course debuts in 2023!

Published December 15, 2022
After a year of preparation and beta testing, DrupalEasy is thrilled to announce our newest long-form course; Professional Module Development! Building on our flagship Drupal Career Online course, Professional Module Development delivers the same level of best-practice-focused training in the authentic manner we are known for. This latest professional development program debuts January 31, 2023. Author and architect for the PMD, (and Drupal Career Online) Michael Anello ( ultimike), infused his 15+ years of experience as a full-time Drupal developer and trainer into Professional Module Development, crafting it in the same thoughtful and methodical way to ensure aspiring Drupal module

Debugging with PhpStorm (Including Drush)

Published April 1, 2014

I recently made the switch from another (several) code editors to PhpStorm based on the recommendations of several members of the Drupal community - not to mention all the postive things I've heard about it on IRC and various other places.

My main motivation for making the switch was the ability to have a integrated debugger - both when running Drupal in a web browser and via Drush. While there are plenty of resources online demonstrating how to set up the debugger, I found that I needed to do a combination of things to make it happen

Getting an error inside a core function? Infinite Redirect? debug_backtrace() to the rescue!

Published April 20, 2011

We are all very familiar with the White Screen of Death in the Drupal world, AKA WSOD. One very common cause is a lack of memory for PHP - yet another is having errors turned off.

In development mode, you should probably make sure you are showing PHP errors on the screen, if this is an option. This is the kind of thing you can edit in your site-specific settings.php file, by using:

Hitting Drush Memory Limit

Published August 6, 2010

We love Drush, Drupal's all-purpose command-line tool, for people who can't stand checkboxes. It's fast, efficient, plays nicely with Version Control Systems like CVS, SVN and Git, and even cleans the kitchen sink. However, after moving our DrupalEasy.com site to a new server we encountered a minor snag. When trying to run even the simplest of Drush commands, we were faced with the following error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 311296 bytes)

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:

Browser FAIL: "Unsupported form of compression" related to PHP notice

Published September 15, 2009

One of my sites had a funny error complaining about an "unsupported form of compression" shortly after installing a new module. The browser would return a white screen of death with an error message (Safari and Firefox).

Content Encoding Error
The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.