Hi,

I've a request regarding the taxonomy_get_tree function, namely with ordering the terms when the i18n module is also installed. At the moment, an "ORDER BY weight, name" clause is built in when retrieving the terms and if one wants to reorder these by translated "name" for example, then that has to be done on a module-by-module basis.

It got me thinking to create some add-on module that would do some processing, but it seems that there is no way to really hook into this function, or rewrite the SQL or theme it or anything really short of using the drupal_override_function module which doesn't seem like a great idea to me.

So, bottom line - do you think it would be possible to either build some additional functionality in the taxonomy module that checks if i18n is installed and acts accordingly; or some hook or something that could facilitate the solving of this issue?

I'm grateful for any kinds of ideas or suggestions, so please let me know.

Thanks a lot,
Martin

Comments

arski’s picture

Hey again,

I have a patch that I just wanted to show you quickly and that works.. wondering if you would put something like this in at all..

Replace in modules/taxonomy/taxonomy.module from ~line 832

    while ($term = db_fetch_object($result)) {
      $children[$vid][$term->parent][] = $term->tid;
      $parents[$vid][$term->tid][] = $term->parent;
      $terms[$vid][$term->tid] = $term;
    }

-- with --

    $termarrays = array();
    $termobjects = array();
    // Translate terms
    while ($term = db_fetch_object($result)) {

      if (module_exists('i18ntaxonomy')) {

        $term->name = tt("taxonomy:term:$term->tid:name", $term->name);

      }
      $termobjects[$term->tid] = $term;
      $termarrays[] = get_object_vars($term);
    }
    
    // Resort terms
    foreach ($termarrays as $key => $row) {
      $weight[$key]  = $row['weight'];
      $name[$key] = $row['name'];
    }
    
    if (isset($weight) && isset($name)) {
      array_multisort($weight, SORT_ASC, $name, SORT_ASC, $termarrays);
    }
    
    foreach ($termarrays as $key => $row) {
      $term = $termobjects[$row['tid']];
      $children[$vid][$term->parent][] = $term->tid;
      $parents[$vid][$term->tid][] = $term->parent;
      $terms[$vid][$term->tid] = $term;
    }

Cheers

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.