diff --git a/includes/modules/taxonomy.inc b/includes/modules/taxonomy.inc index 0659747..659bfad 100644 --- a/includes/modules/taxonomy.inc +++ b/includes/modules/taxonomy.inc @@ -30,10 +30,8 @@ function taxonomy_features_pipe_field_instance_alter(&$pipe, $data, &$export) { $module = $map[$term->uuid]; $export['dependencies'][$module] = $module; } - // Otherwise, add the uuid_term to the export and delegate it - // to the uuid_term export handlers. + // Otherwise, add the uuid_term to the pipe. else { - $export['features']['uuid_term'][$term->uuid] = $term->uuid; $pipe['uuid_term'][] = $term->uuid; } } diff --git a/includes/uuid_term.features.inc b/includes/uuid_term.features.inc index 0ee8203..69091ca 100644 --- a/includes/uuid_term.features.inc +++ b/includes/uuid_term.features.inc @@ -31,41 +31,51 @@ function uuid_term_features_export_options() { * Implements hook_features_export(). */ function uuid_term_features_export($data, &$export, $module_name = '') { + $pipe = array(); + $export['dependencies']['taxonomy'] = 'taxonomy'; $export['dependencies']['uuid'] = 'uuid'; $export['dependencies']['uuid_features'] = 'uuid_features'; - foreach ($data as $uuid) { - uuid_term_features_get_dependencies($export, $uuid); - } - return array(); -} + $tax_map = features_get_default_map('taxonomy'); + $term_map = features_get_default_map('uuid_term', 'uuid'); -/** - * Adds terms and its dependencies to the export. - * - * Parents and term references are handled recursively, other references are not - * yet supported. - */ -function uuid_term_features_get_dependencies(&$export, $uuid) { - $terms = entity_uuid_load('taxonomy_term', array($uuid)); - if (!isset($export['features']['uuid_term'])) { - $export['features']['uuid_term'] = array(); - } - if (!isset($export['features']['taxonomy'])) { - $export['features']['taxonomy'] = array(); - } - if (count($terms)) { - $term = reset($terms); - $export['features']['uuid_term'][$uuid] = $uuid; - $export['features']['taxonomy'][$term->vocabulary_machine_name] = $term->vocabulary_machine_name; - // Recursively add all parents and the references of the parents. + foreach (entity_uuid_load('taxonomy_term', $data) as $term) { + $export['features']['uuid_term'][$term->uuid] = $term->uuid; + + // If the parent taxonomy is already provided by another module, + // remove the taxonomy and add the other module as a dependency. + if (isset($tax_map[$term->vocabulary_machine_name]) && $tax_map[$term->vocabulary_machine_name] != $module_name) { + if (isset($export['features']['taxonomy'][$term->vocabulary_machine_name])) { + unset($export['features']['taxonomy'][$term->vocabulary_machine_name]); + } + $module = $tax_map[$term->vocabulary_machine_name]; + $export['dependencies'][$module] = $module; + } + // Otherwise, add the taxonomy to the pipe. + else { + $pipe['taxonomy'][] = $term->vocabulary_machine_name; + } + + // Add the term's parents. foreach (taxonomy_get_parents($term->tid) as $parent) { - if (!in_array($parent->uuid, $export['features']['uuid_term'])) { - uuid_term_features_get_dependencies($export, $parent->uuid); + // If the parent term is already provided by another module, + // remove the term and add the other module as a dependency. + if (isset($term_map[$parent->uuid]) && $term_map[$parent->uuid] != $module_name) { + if (isset($export['features']['uuid_term'][$parent->uuid])) { + unset($export['features']['uuid_term'][$parent->uuid]); + } + $module = $term_map[$parent->uuid]; + $export['dependencies'][$module] = $module; + } + // Otherwise, add the parent term to the pipe. + else { + $pipe['uuid_term'][] = $parent->uuid; } } } + + return $pipe; } /** diff --git a/uuid_features.module b/uuid_features.module index c4cb1f7..42f16fd 100644 --- a/uuid_features.module +++ b/uuid_features.module @@ -1,6 +1,15 @@