Thanks for your work with taxonomy hierarchy in Drupal. This is fantastic. I'm trying to get the distant parent module and the patches for the taxonomy and taxonomy_context modules to work with 4.6. It seems that distant parent works fine in 4.6, with the minor flaw that it doesn't appear in the admin menu in the standard 4.6 settings location.

As for the patches, you've already noted in your tutorial that some of the breadcrumb functionality (step 1 in your tutorial) has already been implemented in the 4.6 version of the taxonomy module.

Are these other patches also available in a 4.6 version? I tried to hand edit the 4.6 modules with the additional code, but the changes in 4.6 made the old patches result in the following error:

Parse error: parse error, unexpected T_ELSE in /home/gov/alpinecounty/WWW/drupal/modules/taxonomy.module on line 729

Any help you can provide in making this work in 4.6 would be greatly appreciated! Thanks in advance.

Here's the patched code that I tried for the taxonomy module:

/**
* Find all parents of a given term ID.
* Patched to allow cross-vocabulary relationships.
* Patch done by bomarmonk on 2005-04-11.
*/
function taxonomy_get_parents($tid, $key = 'tid') {
if ($tid) {
if ($distantparent) {
// Cross-vocabulary-aware SQL query
$sql_distantparent = 'SELECT t.* FROM {term_data} t, {term_hierarchy} h LEFT JOIN {term_distantparent} d ON h.tid = d.tid '.
'WHERE h.tid = %d AND (d.parent = t.tid OR h.parent = t.tid)';
$result = db_query($sql_distantparent, $tid);
} else {
//Original drupal query
$result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name', $tid);
$parents = array();
while ($parent = db_fetch_object($result)) {
if (function_exists('taxonomy_access')) {
if (taxonomy_access('view', $parent->tid)) {
$parents[$parent->$key] = $parent;
}
}
else {
$parents[$parent->$key] = $parent;
}
}
return $parents;
}
else {
return array();
}
}

...and

/**
* Find all ancestors of a given term ID.
* Patched to call helper functions using the optional "distantparent" argument, so that cross-vocabulary-aware queries are activated.
* Patch done by bomarmonk on 2005-04-11.
*/
function taxonomy_get_parents_all($tid, $distantparent = FALSE) {
$parents = array();
if ($tid) {
$parents[] = taxonomy_get_term($tid);
$n = 0;
while ($parent = taxonomy_get_parents($parents[$n]->tid, 'tid', $distantparent)) {
$parents = array_merge($parents, $parent);
$n++;
}
}
return $parents;
}

Here's what I tried for taxonomy context:

/**
* Return the breadcrumb of taxonomy terms ending with $tid
*/
* Patched to call taxonomy_get_parents_all() with the optional $distantparent argument set to TRUE, to implement cross-vocabulary hierarches.
* Patch done by bomarmonk on 2005-04-11.
*/
function taxonomy_context_get_breadcrumb($tid, $mode) {
$breadcrumb[] = l(t("Home"), "");
if (module_exist("vocabulary_list")) {
$vid = taxonomy_context_get_term_vocab($tid);
$vocab = taxonomy_get_vocabulary($vid);
$breadcrumb[] = l($vocab->name, "taxonomy/page/vocab/$vid");
}
if ($tid) {
// New $distantparent argument added with value TRUE
$parents = taxonomy_get_parents_all($tid, TRUE);
if ($parents) {
$parents = array_reverse($parents);
foreach ($parents as $p) {
// The line below implements the breadcrumb patch
if ($mode != "taxonomy" || $p->tid != $tid)
$breadcrumb[] = l($p->name, "taxonomy/term/$p->tid");
}
}
}
return $breadcrumb;
}

Comments

Jaza’s picture

Getting distantparent and related patches 4.6-compatible is high on my TODO list for Drupal. However, there are two big things stopping me from doing this at the moment:

  1. I'm totally bogged down by non-Drupal work for the next week or two;
  2. I'm waiting for 4.6 stable to be released, so that I have a solid platform for development.

Once these problems go away, I'll look into it.

Jeremy Epstein - GreenAsh

bomarmonk’s picture

Any news on this module (it's been several weeks and 4.6 is now available)? It seems pretty useful... or is this functionality already in 4.6? I guess I can experiment with taxonomy_context and my breadcrumbs and find out. Either way, its good to have contributions like this out there... still have a bit of a learning hill to climb before I can really help out (I can only create simple webforms in PHP and am starting into arrays and loops-- I'll get there).

Jaza’s picture

I've just tested distantparent and its associated patches on a clean install of 4.6. The current version of distantparent (released for 4.5) works perfectly on 4.6. You just unzip the module into your /modules directory, run the SQL to set up the database table, and off you go.

Taxonomy_context has finally been released for 4.6, and I have tested the patches against this new version of taxonomy_context, running on a 4.6 install. None of the relevant functions in taxonomy_context have changed since the patches were written. I was able to replace all the necessary code, and I achieved the correct breadcrumb effect on 4.6. That is, all the original patches still work fine.

Here's what you need to do, once you've installed taxonomy_context and distantparent on Drupal 4.6:
1. Replace the code for all three functions with the code given in the tutorial 'cross-vocabulary taxonomy hierarchies' (http://www.greenash.net.au/posts/thoughts/cross_vocab_taxonomy_hierarchies).
2. Replace the code for the second of the three bugs (the second one is a patch for taxonomy.module - the first and third patches are now incorporated in the new taxonomy_context module) given in the tutorial 'basic breadcrumbs and taxonomy' (http://www.greenash.net.au/posts/thoughts/basic_breadcrumbs_and_taxonomy).

Note that I do NOT guarantee that the patches can still be applied automatically (i.e. using the unix patch utility). I recommend that you copy and paste the necessary code manually.

Re: the menu item not appearing in the 'settings' submenu. The 'distant parents' menu item is not meant to be in the 'settings' submenu, because the admin page is not for configuring the module's settings (the module hasn't got any), it's for managing sets of data. This is also why the 'categories' page is not under 'settings' (because it lets you manage taxonomy terms, not configure the taxonomy module's settings).

I will make a 4.6 branch in CVS, and on the projects page, very soon.

bomarmonk’s picture

Thank you for all of the clear instructions and updates. I'll set about work on this today. Sorry that I wasn't more thorough in my own exploration of the compatibility... maybe my efforts didn't work originally because I was working with an older tax_context mod.

bomarmonk’s picture

A further question: how do I preserve the taxonomy_access patch (keep the tax_access module working) and still apply the patch on the taxonomy.module (the core taxonomy module is already patched for tax_access). My efforts seem to work so far, but I want to make sure I haven't missed something (am I bypassing the tax_access module?)

Here is my attempt to tiptoe around the tax_access patch (thank you for any suggestions on how to better keep both modules working together):

* Find all parents of a given term ID.
* patched for cross-hierarchy (cbm 2005-05-05)
*/
function taxonomy_get_parents($tid, $key = 'tid', $distantparent = FALSE) {
if ($tid) {
if ($distantparent) {
// Cross-vocabulary-aware SQL query
$sql_distantparent = 'SELECT t.* FROM {term_data} t, {term_hierarchy} h LEFT JOIN {term_distantparent} d ON h.tid = d.tid '.' WHERE h.tid = %d AND (d.parent = t.tid OR h.parent = t.tid)';
$result = db_query($sql_distantparent, $tid);
} else {
//Original drupal query
$result = db_query('SELECT t.* FROM {term_hierarchy} h, {term_data} t WHERE h.parent = t.tid AND h.tid = %d ORDER BY weight, name', $tid);
}
$parents = array();
while ($parent = db_fetch_object($result)) {
if (function_exists('taxonomy_access')) {
if (taxonomy_access('view', $parent->tid)) {
$parents[$parent->$key] = $parent;
}
}
else {
$parents[$parent->$key] = $parent;
}
}
return $parents;
}
else {
return array();
}
}