Community & Support

what to do when to_arg() function needs to return an array?

Hi,
I hope someone can help with this - I've been battling for what seems like weeks! I'm developing a module based on SimpleGallery, to include private areas for customers etc. So, the private gallery that becomes available when a customer log on to the site will depend on their user ID (in fact, the user name will match the gallery name). Each private gallery, taxonomy based, may have multiple terms associated with it and the menu should reflect this. I've accomplished a fair amount without using wildcards in the _menu hooks. See http://mphotos.net. That works with this code:

<?php
 
foreach ($tree as $term) {
   if (
taxonomy_term_count_nodes($term->tid)>0) {
    if (
$term->depth == 0) {
     
$items['gallery/'.$term->tid] = array(
       
'title' => $term->name,
       
'description' => $term->description,
       
'page callback' => 'simplegallery_sub',
       
'page arguments' => array(1),
       
'access arguments' => array('access simplegallery'),
       
'type' => MENU_NORMAL_ITEM,
       
'menu_name' => 'menu-gallery',
      );
    } elseif (
$term->depth == 1) {
      foreach (
$term->parents as $parent) {
       
$items['gallery/'.$parent.'/'.$term->tid] = array(
         
'title' => $term->name,
         
'description' => $term->description,
         
'page callback' => 'simplegallery_sub',
         
'page arguments' => array(2),
         
'access arguments' => array('access simplegallery'),
         
'type' => MENU_NORMAL_ITEM,
         
'menu_name' => 'menu-gallery',
        );
      }
    }
  }
}
?>

What I'm stuck on is how to replicate this effect for path like private/%userid/%termid, where the termid actually comes from an array of terms which are children of the vocabulary associated with the particular customer.

This code works when ptid_to_arg() returns an integer.

<?php
  $items
['private/%user_id/%ptid'] = array(
   
'title' => 'this link',
   
'description' => 'this link descript',
   
'page callback' => 'privategallery_sub',
   
'page arguments' => array(1),
   
'access arguments' => array('access customer galleries'),
   
'type' => MENU_NORMAL_ITEM,
   
'menu_name' => 'menu-gallery',
  );

  return
$items;

}

function
ptid_to_arg($arg) {
       
//get user name

        //convert to gallery name

        //get vocabulary id

        //get all terms in this vocabulary

        //return array of terms
       
return 45;
}

function
user_id_to_arg($arg) {
       
$thisuser = $GLOBALS['user'];
        return
$thisuser->uid;
}
?>

Anyone got an idea how I might approach the problem when ptid_to_arg() needs to return an array of integers, thus generating multiple menu items.

Thanks for reading this and for any help you can give me. It's very much appreciated!

Matthew