Export All Feature Components with Drush in Drupal

drush_logo-blackDrush is a tool to interact with Drupal and Features is a community module that allows you package a collection of configuration values and code to be re-usable across project; more typically Features is used by developers to simply move Drupal configuration between your development server and your production server.

In Features and its Admin UI you may select configuration values (which are Exportable — not everything is exportable) and create a Feature select components.

Using the Features Admin UI to complete these tasks for a full website (with dozens of Features perhaps) can get boring, and tedious. It’s much easier at times to do this via the command line and Drush when using Features on your website. Here is a small website Features’ listing that I recently created; each Feature is used to encapsulate a piece of the code/configuration needed for that chunk of the website (a Dashboard admin page, Search pages, Theme coloring, written content on the site — whatever):

Sample Feature usage on a website.

Sample Feature usage on a website.

When creating a Feature to export as an example a custom View to code you would issue the following:

drush features-export newfeature views_mycustomview

But, this is only 1 View … you may have many many such Views and configuration items on the site. Wouldn’t it be nice to be able to use wildcards or something to quickly select all Views into the Feature you want to make? You can! Drush supports this when we review the Help documentation using drush help features-export:

Export a feature from your site into a module. If called with no arguments, display a list of available components. If called with
a single argument, attempt to create a feature including the given component with the same name. The option '--destination=foo'
may be used to specify the path (from Drupal root) where the feature should be created. The default destination is
'sites/all/modules'. The option '--version-set=foo' may be used to specify a version number for the feature or the option
'--version-increment' may also to increment the feature's version number.

 feature                                   Feature name to export.                                                                
 components                                Patterns of components to include, see features-components for the format of patterns.

 --destination                             Destination path (from Drupal root) of the exported feature. Defaults to 
 --version-increment                       Increment the feature's version number.                                  
 --version-set                             Specify a version number for the feature.

Aliases: fee

And then if we look at the help text for drush help features-components:

drush help features-components
List feature components matching patterns. The listing may be limited to
exported/not-exported components.

A component pattern consists of a source, a colon and a component. Both source
and component may be a full name (as in "dependencies"), a shorthand (for
instance "dep") or a pattern (like "%denci%").

Shorthands are unique shortenings of a name. They will only match if exactly one
option contains the shorthand. So in a standard installation, "dep" will work
for dependencies, but "user" wont, as it matches both user_permission and

Patterns uses * or % for matching multiple sources/components. Unlike
shorthands, patterns must match the whole name, so "field:%article%" should be
used to select all fields containing "article" (which could both be those on the
node type article, as well as those fields named article). * and % are
equivalent, but the latter doesn't have to be escaped in UNIX shells.

Lastly, a pattern without a colon is interpreted as having ":%" appended, for
easy listing of all components of a source.

 patterns                                  The features components type to      
                                           list. Omit this argument to list all 

 --exported                                Show only components that have been 
 --not-exported                            Show only components that have not  
                                           been exported.

Aliases: fc

We see that we can indeed to a bulk export of various Components into our Feature upon creation. Exporting all Views on our site would be as easy as:

drush fe my_sample_feature views_*

Looking for quality Drupal Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , | Posted under Drupal | RSS 2.0

Author Spotlight

David Gurba

David Gurba

I am a web programmer currently employed at UCSB. I have been developing web applications professionally for 8+ years now. For the last 5 years I’ve been actively developing websites primarily in PHP using Drupal. I have experience using LAMP and developing data driven websites for clients in aviation, higher education and e-commerce. If you’d like to contact me I can be reached at david.gurba@arvixe.com

Leave a Reply

Your email address will not be published. Required fields are marked *

+ 5 = 8

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>