Blogs

EMAIL: info@example.com

ComputerMinds.co.uk: Nathan’s fix for Rabbit Hole

Rabbit! Photo by Victor Larracuente on Unsplash

In case you’re not aware, this year a bunch of us at CM are taking on a Drupal contribution challenge. Do go read about it!

I managed to squeeze in this contribution BEFORE the challenge started 😅 What a way to start the year!

We have a site that uses a large number of features to manage a large number of taxonomies, and I was tasked with rabbit-holing them all. That is, to make sure that if a user tries to visit any of their term pages, they just get a 404 page. Rabbit Hole is the answer, and lets you configure such things for most entity types that you might want to hide from public view.

Having a large number of features is one thing, but this was also a multi-site installation where we have four sites running off the same codebase – and a fifth in construction! Reviewing each taxonomy and rabbit-holing it, therefore, would take some time.

It turned out, though, that even more time would be spent on the already-slow features export page. Features was unable to recognise that the Rabbit Hole variables created for my taxonomies needed to be exported, and thus just left me with an enormous box of variables to select from!

Fortunately, somebody pointed out that there’s a hook for that!

A few hook_features_pipe_COMPONENT_alter() instances later, and I had nodes and taxonomy terms covered. (see the patch for detail – don’t worry it’s not long!)

There are a bunch of other entity types you might want to do this for, but I didn’t want to get too tangled up. Hopefully somebody can copy the examples I’ve done, with a little extra time for testing, and complete the set. Else, we’ve nicely covered some key bases.

Drupal issue 3050826 has now made progress! Plus, James found some time to review the fix. Thanks James!

It still took a few hours to get databases for all the sites, check the usages of each taxonomy and update the features, but at least the auto-dependencies button worked – a nice chunk of time saved by fixing something for the community, hurrah! 🥳

(Photo by Victor Larracuente on Unsplash)