Updating Features and Adding Components Using Drush
Posted on 21st October 2014
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.
If you use the Features module to manage your Drupal configuration, it can be time consuming to update features through the UI, especially if you are working on a remote server and need to keep downloading and uploading files.
If you re-create a feature through the UI, you'll be prompted to download a new archive of the feature in its entirety onto your local computer. You could either commit this into a local repository and then pull it remotely, or use a tool such as SCP to upload the archive onto the server and commit it from there. You can simplify this process by using Drush.
To search for a component, use the
drush features-components command. This will display a list of all components on the site. As we're only interested in components that haven't been exported yet, add the
--not-exported option to filter the results.
To filter further, you can also use the
grep command to filter the results. For example,
drush features-components --not-exported field_base | grep foo, would only return non-exported field bases containing the word "foo".
The result is a source and a component, separated by a colon. For example,
Exporting the Feature
Once you have a list of the components that you need to add, you can export the feature. This is done using the
drush features-export command, along with the feature name and the component names.
$ drush features-export -y myfeature field_base:field_foo field_instance:user-field_foo
In this example, the base for field_boo and it's instance on the user object is being added to the "myfeature" feature.
If you are updating an existing feature, you'll get a message informing you that the module already exists and asking if you want to continue. This is fine, and is automatically accepted by including
-y within the command. If a feature with the specified name doesn't exist, it will be created.
If you're creating a new feature, you can define where the feature will be created using the
Once complete, you will see a confirmation message.
Created module: my feature in sites/default/modules/custom/features/myfeature
Once finished, the feature is updated in it's original location, so there's no download of the feature and then needing to re-upload it. You can add and commit your changes into Git or continue with your standard workflow straight away.
About the Author
Oliver Davies is a Full Stack Web Developer and System Administrator based in the UK. He is a Senior Developer at Microserve and a part-time freelancer specialising in Drupal, Symfony and Laravel development and Linux systems administration.