Problem/Motivation
I am creating some tools for provision + hostmaster tasks.
hook_hosting_tasks() defines "task types", but you can only use the hosting task form (generated by hosting_tasks_TASK_TYPE_form()) with one word task types.
Since the "task type" name has to match a drush command "provision-TASK_TYPE" this breaks naming convention for drush commands, ie. using dashes instead of underscores.
Proposed resolution
Replace all dashes with underscores when looking for a hosting_tasks_TASK_TYPE_form() function.
Remaining tasks
None, as far as I can tell.
User interface changes
None.
API changes
You can now use more than one word (separated by dashes) for task type names
Patch coming...
Comments
Comment #1
jon pughPatch attached
Comment #2
steven jones commentedComment #3
jon pughWorking patch, sorry bout that
Comment #4
steven jones commentedI think that for 2.x, yes, we should do this, but for 1.x I don't see much point, you can just define your multi-word tasks using underscores, and Drush happily deals with that.
We should also clean up provision and everywhere else to use hyphens for Drush commands.
Comment #5
steven jones commentedComment #6
jon pughThis sounds like a contradictory recommendation. Are you recommending I use underscores in my drush commands while saying provision should use hyphens? Also, "provision-" is automatically appended to my hosting task name to come up with the appropriate drush command, for my project, the drush command would have to be "
drush provision-devshop_syncwhich, to me, is going backwards.hostmaster doesn't string replace hyphens to underscores when looking up a hook. It should. Form API does the same thing, as do other subsystems of Drupal.
Functions must use underscores. Template files, form IDs both do replacement one way or another. Drush commands use hyphens. This one line change would make it work much like the rest of Drupal does.
I COULD make all of my drush commands use underscores, but then, because
Hosting.module does not convert hyphens for underscores when looking for its hooks. That to me is a bug.
Due to the architecture of hosting.module, in this code,
"provision-$task"MUST be a valid drush command. If the drush command is more than one word, it should be hyphenated, which breaks hook lookups.Comment #7
steven jones commentedWhat I mean is that for 6.x-2.x we should do as you say, and change provision to use hyphens when calling drush, but for 1.x, I'm not 100% sure we should worry about it. I know its just a one-line change, but I'm not 100% sure of the ramifications of that change.
Comment #8
steven jones commentedNeed to get the patch from #3 cleaned up and existing tasks cleaned up in 6.x-2.x
Comment #9
jon pughPatch attached for 1.9. I need to start here, If approved for 1.9 I'll make it for 2.x and 1.x.
I still think this is a valid backport. What did you mean by:
I didn't see any changes needed in provision, but maybe thats because I haven't dug into 2.x yet.
Comment #10
jon pughAttached is a patch to 2.x-dev branch of hostmaster.
Comment #11
fastangel commentedAttached new patch with other hooks with the same problem. http://drupal.org/node/1778400
NOTE: For version 1.9
Comment #12
steven jones commentedPatch in #11 looks good on first inspection.
Comment #13
steven jones commentedHmm...maybe not the actual patch file, which does the following for me:
fatal: corrupt patch at line 34Comment #14
fastangel commentedResolved the problem.
Comment #15
jon pughChanging the title to reflect the real issue.
I wonder how drupal core handles this... they switch _ to - and back again for templates, menu items, etc.
/me runs to api.drupal.org....
Same way as us! That's kind of funny... so I guess we are doing this "right"? I gotta admit, it does seem a bit hacky that drupal itself doesn't have a global function to convert dashes to underscores...
Comment #16
steven jones commentedThanks guys, I've pushed the patch from #14 (plus a tiny fix) into 6.x-1.x and now I'll start the work properly converting the tasks in 6.x-2.x.
Comment #17
fastangel commentedAttached the patch for version 6.x.2
Comment #18
steven jones commentedThis was slightly more complicated in 2.x as we wanted to rename our tasks too, which I've done in provision and hostmaster. Thanks everyone!