User login

How to create a Feature without the initial download through the UI

If you hate downloading and unzipping the initial feature you create as much as i do, because you haven't bothered with that foolishness since Drush, this post is for you.

This is the minimal information needed (from my experimentation) for Features to recognize your module as a Features module. Then you can add variables and other features through the UI (or Drush), and drush fu feature_example to update your module code (where feature_example is the name of your feature) and fu stands for features-update.

In feature_example.info:

core = "7.x"
dependencies[] = "features"
dependencies[] = "strongarm"
description = "Enables ability to add people."
features[ctools][] = "strongarm:strongarm:1"
name = "Example feature"
package = "Features"
php = "5.2.4"

In feature_example.module

<?php
/**
 * @file
 * Code for the People feature.
 */

include_once('feature_example.features.inc');
?>

In feature_ax.features.inc:

<?php
/**
 * @file
 * feature_ax.features.inc
 */

/**
 * Implementation of hook_ctools_plugin_api().
 */

function feature_ax_ctools_plugin_api() {
  list(
$module, $api) = func_get_args();
  if (
$module == "strongarm" && $api == "strongarm") {
    return array(
"version" => 1);
  }
}
?>

Adding Features to Your Feature

The most important thing to understand (i didn't) is that the user interface for features is completely meaningless if you are not going to click the Download button. Instead, when you need to add a feature, simply add it to the .info file. In a feature that does not have Views at all, you can trigger drush fu to generate that code just by adding the following— marked with pluses.

++ b/web/sites/all/modules/custom/feature_awards/feature_awards.info
@@ -4,6 +4,7 @@ dependencies[] = "features"
dependencies[] = "link"
dependencies[] = "node_reference"
dependencies[] = "strongarm"
+dependencies[] = "views"
description = "Provides an award content type for other features"
features[ctools][] = "strongarm:strongarm:1"
features[field][] = "node-award-field_awarded_to"
....
features[variable][] = "menu_parent_award"
features[variable][] = "node_options_award"
features[variable][] = "node_submitted_award"
+features[views_view][] = "projects"
name = "SDL Awards Feature"
package = "Features"
php = "5.2.4"

It will then create the hook_views_api() implementation and the feature_awards.views_default.inc file for you. Just a quick edit of the .info file. It will even add requirements you need to that same .info for you.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.