Ed

Hi! I’m Ed, and it’s been nearly nine years since I first discovered Drupal (version 8 back then). Since that moment, I’ve worked on hundreds of projects, each teaching me something new about Drupal’s architecture, quirks, and capabilities. Over time, I started jotting down useful snippets, fixes, and discoveries, most of which sat scattered across my Google Keep notes.

Eventually, I decided those insights deserved a proper home. This site collects the most valuable, interesting, and occasionally fun parts of my journey through Drupal development.

I built this site with Drupal 11, Next.js, and TailwindCSS.

Welcome. If you have questions, ideas, or suggestions, you can reach me on LinkedIn.

Latest Notes

Search

How to alter the Route based on its parameters

The client recently asked me:

“I want to change how the Taxonomy Vocabulary page works. It should have a custom filter and more columns, but you should keep the default functionality like sorting, hierarchy, etc. Also, I want this change to apply only to a few vocabularies, not all of them.”

Most of us are familiar with Route Subscribers, which can be used to alter route defaults. However, they’re executed before the actual request, so we don’t have access to the real values of the route parameters — meaning we can’t make decisions based on them.

That’s where the Route Enhancer comes into play.

Read More

Drupal Modal: add click callback to the modal button

The client wanted for a button in the modal to add the product to the cart. The button was rendered dynamically via a dialog options attribute.

We all know that Drupal automatically moved form buttons into the jQuery UI dialog buttons pane. We also know that we can supply custom buttons via the data-dialog-options attribute. But it's impossible to supply a click callback for a button via the data-dialog-options attribute.

Read More

Update max length for the existing text field

You may need to do this if you didn't use text long when creating a field and are now building a custom migration, and some source values are too long for the field you created🙄

If you need to do it in a live environment, use the following code snippet to create a custom Drush command or an update hook. In my case, I just run it as a script locally because the situation allowed it.

Read More

CSS: make a component full-width

Often, when supporting older projects, you can't make significant changes and must work within existing constraints. You may then need to render a newly created hero banner on a page with limited width.

Use this CSS to make an element full-width even if the block's parent has max-width:
margin-left: calc(50% - 50vw);
margin-right: calc(50% - 50vw);

When dealing with a LAMP server

Remember to run this command after modifying Apache configurations to ensure everything is working correctly.

apachectl configtest

Easy way to customize "required" error on forms

Drupal keeps surprising even after so many years :) Just set the #required_error attribute to the desired message in the form element render array.

I remember back in the days we would use \Drupal::messenger() to clear the messages and set our own error if needed the custom texting. LOL

Responsive remote videos

Drupal renders remote videos as iframes. Here is how you can set a ratio for an iframe to make it behave similarly to the HTML <video> tag? This is applicable to more than just videos.

Read More