Skip to main content

Nathan's fix for Rabbit Hole

CM Drupal Contribution Challenge 2020
An article from ComputerMinds - Building with Drupal in the UK since 2005
4th Feb 2020

Nathan Page

Developer
Hey, you seem to look at this article a lot! Why not Bookmark this article so you can find it easily in the future?

This year, a bunch of us at ComputerMinds are challenging ourselves to make a Drupal contribution every single month. We'll be making patches, helping solve problems, providing translations, discussing issues and more! In this article series, we'll be writing about our favourite and most-interesting contributions, and making some loud noises in support of the amazing Drupal community.

Read more

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)

Hi, thanks for reading

ComputerMinds are the UK’s Drupal specialists with offices in Bristol and Coventry. We offer a range of Drupal services including Consultancy, Development, Training and Support. Whatever your Drupal problem, we can help.