Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Turning Your Custom Drupal Module into a Feature

Parent Feed: 

Warning: This post is over a year old. I don't always update old posts with new information, so some of this information may be out of date.

Yesterday I was fixing a bug in an inherited Drupal 7 custom module, and I decided that I was going to add some tests to ensure that the bug was fixed and doesn’t get accidentially re-introduced in the future. The test though required me to have a particular content type and fields which are specific to this site, so weren’t present within the standard installation profile used to run tests.

I decided to convert the custom module into a Feature so that the content type and it’s fields could be added to it, and therefore present on the testing site once the module is installed.

To do this, I needed to expose the module to the Features API.

All that’s needed is to add this line to the mymodule.info file:

features[features_api][] = api:2

After clearing the cache, the module is now visible in the Features list - and ready to have the appropriate configuration added to it.

'The features list showing the custom module'

Questions? Comments? I’m @opdavies on Twitter.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web