I'm starting the "hard" part of my first module (WiSoul.module) and I need to split the form of the edit page in two tabs ("Trak" tab & "Waypoints" tab).
Following, but not fully understanding, the following tip http://groups.drupal.org/node/8386, in the hook_menu I put the code :

    $items[] = array('path' => 'WiSoul',
      'title' => t('WiSoul Track Edit'),
      'description' => t('Edit the WiSoul track'),
      'access' => user_access('edit own WiSoul'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('WiSoul_test')
    );
    $items[] = array('path' => 'WiSoul/track',
      'title' => t('Track'),
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );
    $items[] = array('path' => 'WiSoul/waypoints',
      'title' => t('Waypoints'),
      'access' => user_access('edit own WiSoul),
      'callback' => 'WiSoul_form_subfolder',
      'type' => MENU_LOCAL_TASK,
      'weight' => 1,
    );

But I cannot se the tab.
I'm not sure about the path of the menu itmes of the edit page, I also tried "Wisoul/edit", "node/edit" and others with no results.
Where am I wrong?

Thanks
Marcello

Comments

usonian’s picture

Assuming you want the 'Track' tab to display your `WiSoul_test` form, try setting your second $items[] =array to:

    $items[] = array('path' => 'WiSoul/track',
      'title' => t('Track'),
      'access' => user_access('edit own WiSoul'),
      'callback' => 'drupal_get_form',
      'callback arguments' => array('WiSoul_test')
      'type' => MENU_DEFAULT_LOCAL_TASK,
    );
nevets’s picture

Is this a custom content type based on node?

m.gribaudo’s picture

I 'we also tried something like this

$items[] = array('path' => "node/". arg(1) . "/edit",
...

with crazy results

nevets’s picture

In that case you need something like the following. The two key parts are since you are adding a tab to a node the path needs to start with node/{nid} and the menu item can not be cached since it depends on the current path. So something like

function your_module_name_menu($may_cache) {
  $items = array();
  if ($may_cache) {
		// Other possible menu items
  }
  else {
    if (arg(0) == 'node' && is_numeric(arg(1))) {
      $node = node_load(arg(1));
      // Change the following line to reflect your node type
      $type = 'mytype';
      if ($node->nid && $node->type == $type ) {
        $items[] = array('path' => 'node/'. arg(1) .'/waypoints',
		      'title' => t('Waypoints'),
		      'access' => user_access('edit own WiSoul'),
		      'callback' => 'WiSoul_form_subfolder',
                      'callback arguments' =>array($node)
          'weight' => 1,
          'type' => MENU_LOCAL_TASK);
      }
    }
  }

  return $items;
}

should work. Note is passes the current node as an argument to WiSoul_form_subfolder().

m.gribaudo’s picture

It work's perfectly!

m.gribaudo’s picture

Following your suggestion the tab has been now correctly inserted.
But when I click on that tab, the page title (and in my theme the corresponding title before the node) change from the node name to the value "View" (is the name of the first tab).
How can I manage this problem?

Thanks

nevets’s picture

Well you should not be defining a tab labeled 'View' (the node module does). Regardless each tab has an associated callback. The page title by default is the tab title but your callback function can call drupal_set_title() to set has desired.