Skip to main content

Using Features Override to manage changes to a distribution

Published on

The Features module has become a de facto tool in configuration management in Drupal 7. In fact, most Drupal distributions now utilize Features to export configuration and handle updates to the configuration. There is one pitfall - Features was  meant to be a way to export a feature set. Features takes a set of configurations and its job is to ensure those are in place. That means customizations to defaults are at risk of preventing incoming changes or loss when updating. That’s not good! You’re using a Drupal distribution so you save time, but now you have headaches because customizations disappear.

There's also been a few updates since I first wrote this blog, check the updates at the bottom.

What is Features Override, then?

That’s where Features Override comes in and allows you to revert your feature modules and ensure configuration sticks. The name of the module speaks to its purpose. It allows you to override a feature and export those changes. But, how? Chaos Tools provides its own alter hooks for its object CRUD API. That means Views, Page Manager, Panels, and any item implementing this CRUD can be exported as a glob of PHP code representing an associative array of objects. Entity API  has its own CRUD, too; without knowing much of the history I’d assume Entity API’s implementation was modeled after Chaos Tools.  The biggest difference is the Entity API utilizes JSON for moving items around. Features, itself, provides its own alters for items that don’t have an import/export definition - such as field bases, field instances, etc. Features Override is a UI for writing alters in your feature module.

Let’s Do This!

We’ll run through customizing Commerce Kickstart 2 - the most download distribution which gets pretty customized. As a disclaimer, I am a maintainer of the project. If you were to install Commerce Kickstart 2 and navigate to Structure -> Features (admin/structure/features) you’d see something like the following:

“Default” means the Features is in its expected state. If we added a new config export or tweaked something, you’d receive it on update. Let’s change that because we want the Blog Post content type to hide the category and tag fields when we’re displaying them as a teaser.

In the above we’ve marked Category and Tags as hidden. In fact, since CK 2.27 there has been an automated test checking this change and Features Override. That’s right - we have automated testing to ensure your changes live on using Features Override (boom.) Let’s look back at our Features.

Now we’re going to create a new Feature called “CK2 Overrides” that will contain our specific changes. That will allow us to upgrade Commerce Kickstart 2 and revert its feature modules and keep our own changes. From the Manage Features page, we will select “Create Feature.” The next step is to pick your “Feature Overrides” component.

So this is where it can get confusing. As you can see there are two component types: “Feature Overrides” and “Feature Overrides (individual — advanced)” Unless you know what you’re doing - just pick the former. Feature’s magic will auto-populate what specific individual overrides are required to be exported. Think of it as nitpicking what specific keys in an array export it needs to alter (because that’s what it is!) Generate or download your feature and enable it!

And now we have nothing overridden! Note: sometimes you'll need to go back and revert the "base" Feature.

Tips and Tricks

It’s not perfect - nothing is. So here’s a few tips and tricks I’ve learned

  • Not all overrides are caught, not all overrides want to stick.
  • Enabling an overrides feature sometimes needs caches cleared to kick off a new features component rebuild. Manually reverting won’t kick over the “overridden status."
  • An override feature will show up as overridden if the base feature is overridden - sometimes you just need to revert that one.

Addendum

Posting a little update! Earlier today in IRC heddn directed me to a patch which improves Features Override. The patch has to do with missing some overrides due to logic in its recursive functions. I have yet to test it, but it is green-lit at RTBC and looks promising: https://www.drupal.org/node/2232999

Mike Potter, the brilliant developer behind Features and Features Override also wrote an article earlier in the year. His blog goes into great detail the overall issues faced with Features (which I lightly touched here.) I highly recommend reading How to Override Features if you'd like to dive into more on the topic.

I'm available for one-on-one consulting calls – click here to book a meeting with me 🗓️