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

yhahn - November 6, 2009 - 21:22
Status:active» fixed

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

q0rban - November 7, 2009 - 13:40
Title:Create an API for enabling and disabling features» Create an API for enabling features
Status:fixed» active

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

q0rban - November 7, 2009 - 14:29
Status:active» needs work

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... ;)

AttachmentSize
features-616222-3.patch 2.63 KB

#4

q0rban - November 7, 2009 - 14:38
Title:Create an API for enabling features» Create an API for enabling and installing features

Whoops, saw a mistake with that one. (still untested)

AttachmentSize
features-616222-4.patch 2.64 KB

#5

yhahn - November 9, 2009 - 04:58
Assigned to:Anonymous» yhahn
Status:needs work» active

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

q0rban - November 9, 2009 - 13:45

It pains me that features needs to implement an API function for installing a module and all of its dependencies

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

yhahn - November 18, 2009 - 05:40
Status:active» fixed

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 parallels drupal_install_modules() which it improves upon.

#8

q0rban - November 18, 2009 - 13:31

Nice! :)

#9

q0rban - November 18, 2009 - 21:20
Status:fixed» needs work

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

yhahn - November 18, 2009 - 22:11
Status:needs work» fixed

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

System Message - December 2, 2009 - 22:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.