Create an API for enabling and installing features
q0rban - October 27, 2009 - 19:55
| Project: | Features |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | yhahn |
| Status: | closed |
Description
Currently all the enabling and disabling code for features lives inside the submit handler for the features form. It'd be nice if these were broken out into separate functions so that if one needs to override the submit handler they can still ensure that they are using the most up to date functions and methods for enabling/disabling features. ;)

#1
There is an api for enabling/disabling features...
http://api.drupal.org/api/function/module_enable/6
http://api.drupal.org/api/function/module_disable/6
#2
heh. I'll try and make a patch for this so you can see what I mean. module_enable doesn't check to see if anything needs to be installed.
#3
Ok, here's a quick (and completely untested) patch so you can at least see what I mean. The point of all this is so that if anything ends up changing in how features are enabled and installed (for instance, maybe _features_export_maximize_dependencies() gets replaced or removed or something), other modules that may make use of the API don't have to care. All they are doing is passing an array of features they want installed. Right now I have a few modules that have a lot of duplicate code from the current features_form_submit() function that would be completely gone if this features_features_install function existed. Every time a new version of features comes out I wonder if something I've copied and pasted has changed in features_form_submit(). Hope you can make sense out of all that... ;)
#4
Whoops, saw a mistake with that one. (still untested)
#5
Point taken. It pains me that features needs to implement an API function for installing a module and all of its dependencies (I hope there is one in D7 core?) but it's certainly something we can make happen.
#6
Yeah, I was definitely surprised the first time I wanted to programmatically install a module that module_enable didn't check to see if anything else needed to be done (installation tasks, check dependencies).
I agree it is a bit silly to have to do this, but at the same time, I consider it good practice to pull out as much actual functionality from all submit handlers and get them in separate functions that just take arguments. There's a bunch of instances in core that in order to do something programmatically, you have to copy and paste most of the code from the submit handler to your own function. Off the top of my head, I think deleting menu items is an example. IIRC, there is no menu_item_delete() function.
#7
Commited: http://drupal.org/cvs?commit=290574
I renamed the API function to
features_install_modules()since it will work with any array of modules and also because the function name parallelsdrupal_install_modules()which it improves upon.#8
Nice! :)
#9
I think this may still need work, as it currently doesn't check to see if features conflict before enabling/installing them. Not sure the best way to go about this, b/c drush enable wouldn't check for this either. We may need a 'drush features enable' command.
#10
Ok, one more shot. I've moved the conflict detection API functions into features.module proper (http://drupal.org/cvs?commit=290914) so you can make use of them prior to calling an install function.
#11
Automatically closed -- issue fixed for 2 weeks with no activity.