This is a patch that adds special support for feature exports that provide code for "hook_enable" and "hook_disable", like the Exportables module does for taxonomy vocabulary and terms.

Basically, since taxonomy vocabulary and terms don't have real default hooks, Exportables emulates this by syncing to the database during hook_enable and hook_disable. This is all fine, except that Exportables provides (or rather, will provide once this patch is finalized and accepted: #645596: Patch to export taxonomy terms) two seperate components: taxonomy_vocabulary and taxonomy_term. If they are both used in the same feature, "hook_enable" and "hook_disable" will be written twice, creating a name conflict.

So, this patch causes the following to happen:

  • A mymodule.install file will be created (but only for modules that don't already exist, just like mymodule.module) that defines a "hook_enable" and "hook_disable" which simply include "mymodule.features.inc" and call "_mymodule_enable" and "_mymodule_disable". Here is an example generated using the patch:
    /**
     * Implementation of hook_enable().
     */
    function mymodule_enable() {
      module_load_include('inc', 'mymodule', 'mymodule.features.inc');
      $args = func_get_args();
      return call_user_func_array('_mymodule_enable', $args);
    }
    
    /**
     * Implementation of hook_disable().
     */
    function mymodule_disable() {
      module_load_include('inc', 'mymodule', 'mymodule.features.inc');
      $args = func_get_args();
      return call_user_func_array('_mymodule_disable', $args);
    }
    
  • The hook implementation for each component will be renamed to include the component name, ie. mymodule_enable_taxonomy_vocabulary() and mymodule_enable_taxonomy_term(). There are otherwise treated normally.
  • A _mymodule_enable() and _mymodule_disable() will be put mymodule.features.inc which calls all component enable and disables. For example, here is _mymodule_enable() as generated by the patch:
    /**
     * Helper to implementation of hook_enable().
     */
    function _mymodule_enable() {
      mymodule_enable_taxonomy_term();
      mymodule_enable_taxonomy_vocabulary();
    }
    

    One random note about the above, these are listed in the inverse logical order: vocabularies should happen before terms. But I'm not sure how to deal with that yet, but this patch is a first step to this working at all..

Please let me know what you think. There are probably bugs or issues I didn't think of with the patch.

Thank you,
David.

Comments

dsnopek’s picture

StatusFileSize
new3.18 KB

Quick fix to the original patch! I forgot to put "<?php" at the top of the install file. This is what I get for not doing enough testing before posting the patch.

mrfelton’s picture

I'm a little confused about what each of the various patched currently doe and doesn't do, and what I need to do to get taxonomy import/export/syncronisation working. Subscribe.

dsnopek’s picture

It depends on what you need. If you just need to include a taxonomy vocabulary in a feature without its terms, just install the current development version of "exportables". This will give you what you need.

What I am working on is getting the taxonomy terms included too. For that you need both this patch and this one to exportables: #645596: Patch to export taxonomy terms

Then its just matter of creating machine names for your vocabulary and terms (I've been doing it right in the database, adding entries to "exportables_machine_names") and adding lines like the following to your *.info file:

features[taxonomy_vocabulary] = "vocabulary1"
features[taxonomy_term] = "term1"
features[taxonomy_term] = "term2"
brad.bulger’s picture

i have just spent a week writing custom code for a feature to do this very thing and did not look forward to having to do it again. this feature feature would be great. subscribing.

dsnopek’s picture

It would be nice to hear from features developers and see if this type of patch has any chance for acceptance.

If not, then I'll modify the code in "exportables" to not directly use hook_install() and hook_uninstall(), but instead require users to write their own. Of course, it would be nice if taxonomy support could be completely automatic, like all the exportable objects that features supports, but getting something upstream -- so that all users can take advantage of it -- is definitely more important.

Thank you,
David.

todd nienkerk’s picture

Subscribing.

m_z’s picture

Subscribing.

q0rban’s picture

Status: Needs review » Needs work

This seems a bit hacky to me..

dsnopek’s picture

@q0rban: Yeah, its far from perfect. I'm about to abandon this patch in my setup and just put custom hook_enable() and hook_disable() in my features that integrate with exportables. Thats also not ideal (ie. much less automatic), but its a much cleaner approach.

dsnopek’s picture

Status: Needs work » Closed (won't fix)

This approach appears to be a dead end! Continued attempts to integrate taxonomy into features will continue in the "exportables" module: #645596: Patch to export taxonomy terms