I'm working on a multilingual site using both i18n and node hierarchy. Each content is both available in french and english.
When using node hierarchy and submitting a new content, the parent pulldown menu on the submit form displays all the nodes, without filtering them according to the current langage.

To correct this issue, I've changed few lines in node_hierarchy.module

Instead of (line 935)

/**
 * Get the items for the parent selector pulldown.
 */
function _nodehierarchy_get_parent_pulldown_items( $parent_id, $types, $child_node = null, $depth = 0 ) {
  $out = array();
  $query = "SELECT * FROM {node} n, {nodehierarchy} h WHERE h.nid = n.nid AND h.parent = %d AND n.type IN (". implode( ",", $types ) .") ORDER BY n.title ASC";
  $result = db_query($query, $parent_id);  
  while ($hierarchylist = db_fetch_object($result)) {
    if ($hierarchylist->nid != $child_node && node_access('update', $hierarchylist)) {
      $out[$hierarchylist->nid] = str_repeat('--', $depth) .' '. $hierarchylist->title;
      $children = _nodehierarchy_get_parent_pulldown_items($hierarchylist->nid, $types, $child_node, $depth+1);
      $out += $children;
    }
  }
  return $out;
}

I use

/**
 * Get the items for the parent selector pulldown. If i18n is enabled, only get nodes in current langage (using path)
 */
function _nodehierarchy_get_parent_pulldown_items( $parent_id, $types, $child_node = null, $depth = 0 ) {
  if (module_exists('i18n')) {
    $path = _i18n_get_original_path();
  	$language = i18n_get_lang_prefix($path);
  	$query = "SELECT * FROM {node} n, {nodehierarchy} h, {i18n_node} l WHERE h.nid = n.nid AND l.nid =h.nid AND h.parent = %d AND n.type IN (". implode( ",", $types ) .") AND l.language = '".$language."' ORDER BY n.title ASC";
    }
    else {
    $query = "SELECT * FROM {node} n, {nodehierarchy} h WHERE h.nid = n.nid AND h.parent = %d AND n.type IN (". implode( ",", $types ) .") ORDER BY n.title ASC";
    }  
  $out = array();
  $result = db_query($query, $parent_id, $language);  
  while ($hierarchylist = db_fetch_object($result)) {
    if ($hierarchylist->nid != $child_node && node_access('update', $hierarchylist)) {
      $out[$hierarchylist->nid] = str_repeat('--', $depth) .' '. $hierarchylist->title;
      $children = _nodehierarchy_get_parent_pulldown_items($hierarchylist->nid, $types, $child_node, $depth+1);
      $out += $children;
    }
  }
  return $out;
}

I think this is a mandatory feature to use node_hierarchy on a multilingual site... at least for me.
Maybe this hack could be improved to allow the language selection using other criteria than the path...
Hope this will help people lost in the maze of drupal 5.x multilinguism...

Comments

markhalliwell’s picture

Component: Code » Drupal/PHP Code

This issue pertains to the 5.x branch which is no longer supported. If this issue cannot be resolved within two weeks, it will be closed.

markhalliwell’s picture

Assigned: chapo » ronan
Category: task » bug