Drupal development like a Boss using Drush and Features
So you already know all about Drush and Features, good for you!
Using Features is a critical tool to create maintainable websites and makes pushing configuration changes between server environments really easy and Drush is a Drupal developer's best friend.
Now, as you all might now, Features has some nice Drush integration and it's really easy to update ("recreate") Features using the command line with drush fua (features-update-all). You might also know about using drush fr (features-revert) to quickly revert a feature.
If you're more savvy you might also know how to list all features using drush fl (features-list) and view diffs for your features using drush fd (features-diff).
The Problem
That's all well and good but what happens if you want to recreate a Feature and add something new to it. If you're going back to the Admin UI, adding new components, downloading the Feature and copying it into your site, you're doing it wrong! This process is tedious and time-consuming and, as usual, there's a better way!
The Solution
Enter, drush fe (features-export). The syntax can be a bit confusing but, once you get used to it, I guarantee it will change your life!
drush features-export NAME_OF_FEATURE_TO_EXPORT SOURCE1:COMPONENT1 [SOURCE1:COMPONENT2 SOURCE2:COMPONENT3 ... SOURCEt:COMPONENTm]
Lets break it down:
- The first parameter is the name of the feature you want to export. This can be either an existing feature you want to add something to or a new one you want to create.
- All subsequent parameters are components you want to add to a feature, using the following syntax: "component_type:component_machine_name".
For example:
# Exports a View with machine name "my_view".
drush fe my_feature views:my_view# Exports the Article content type.
drush fe my_feature node:article# You can add as many components as you want in a single line:
drush fe my_feature node:article views:article_listing taxonomy:article_tags
It's really that easy! The tricky part can be knowing what to call each component name, so here's a quick cheat-sheet:
- "context": Contexts
- "image": Image Styles
- "field": Fields (note that Fields get automatically added when you export a Content Type that uses them)
- "filter": Text Formats
- "menu_custom": Menus
- "menu_links": Menu Links
- "node": Content Types
- "rules_config": Rules
- "taxonomy": Taxonomy Vocabularies
- "user_permission": Permissions
- "user_role": Roles
- "variable": Variables (using Strongarm)
- "views": Views (its technically "views_view", but "views" is shorter and works just fine)
This list only covers the most common components and contributed modules may define their own so a quick way to find out is to go to the features Admin UI and check out the components select box or, as Mikko pointed out, use drush fc (features-components) to list all components in the terminal.
Bonus
The features-export command has a switch which allows you to increment version numbers automatically! I wrote about that a while ago, check it out if you want to jog your memory: Automatically increment Features version numbers using Drush.
Now go create a Feature without touching the Admin UI and smirk at your colleagues who are still pointing and clicking while you're getting ready to leave early! ;)
As usual, for further reading check out the documentation on Drupal.org.
Tags:
21Nov2012
Language
English
Category:
Series:
Reviewed: Yes