Hello

I would like to create a dynamic menu in function of values which are contain in the profile_values table. I'm searching a way to define the parent item in hook_menu where I would like to place this item. I cannot do this manually because I don't know which values will be in the Database. By default all item go into the default menu "Navigation" and I would like to place it in a custom menu "Application".

This code display the item in "Navigation":

$items[] = array(
  'title' => t('Human Resources'), 
  'path' => 'hr',
  'access' => 'TRUE'
);

Is it possible to place this item in the parent item called "Application" like this ?

$items[] = array(
  'title' => t('Human Resources'), 
  'path' => 'Application', 'hr',
  'access' => 'TRUE'
);

Cheers,
Damien
----------------
Keep Open Spirit

Comments

traxer’s picture

On the menu administration page, you can change the "Human Resources" item to be displayed in the "Application" menu. All children of "Human Resources" (i.e. 'path'=> 'hr/whatever') will then still be displayed as children of "Human Resources".

I hope this helps.
--
~/.singatrue: file not found

dsnoeck’s picture

Thanks for the proposition, unfortunately that's not answer to my needs.

In my example, Human Resources doesn't have children item.

I have:
- A menu called Application, displayed in the left sidebar as a block
- zero or more menu items (depend of one value caught from LDAP)

These items are display like this :

$items[] = array(
  'title' => t('Human Resources'),
  'path' => 'application/humanresources', 
  'access' => 'TRUE',
);

And I cannot go to the administration page to define the parent item of Human Resources, because these items are displayed in function of a value caught from LDAP. So, for one user, there could be just one item, and for an other user there could be ten items.

I hope this is more clear.

Cheers,
Damien
----------------
Keep Open Spirit

- Damien
:: Keep Open Spirit ::

traxer’s picture

Create a designated parent item in hook_menu for the items that depend on LDAP. Move that item to the Application menu and deactivate it.

--
~/.singatrue: file not found

dsnoeck’s picture

Thanks Traxer, that's works fine now.

- Damien
:: Keep Open Spirit ::

aklump’s picture

/**
 * GOAL AND STRATEGY:
 *
 * node/6 is a top level menu item in a custom menu called 'menu-main-menu'. I'm
 * creating a child menu item using hook_menu with the path of 'member/pick'. I
 * want this menu item to be rendered as a child of node/6 in the main menu, and
 * I want all of this to happen programatically.
 * 
 * Here's how...
 * 
 * 1. Create the child item using hook_menu
 * 2. In hook_menu_link_alter, lookup the mlid of node/6 and apply it as the
 * plid of the child item
 * 
 */

/**
 * Implementation of hook_menu()
 */
function hook_menu() {
  $items = array();
  $items['member/pick'] = array(
    'title' => 'Member Pick',
    'menu_name' => 'menu-main-menu',
    'page callback' => 'member_pick_page',
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
  );    
  return $items;
}

/**
 * Implementation of hook_menu_link_alter
 */
function hook_menu_link_alter(&$item) {
  if ($item['page callback'] == 'member_pick_page') {
    $parent_normal_path = 'node/6';
    $plid = db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_path = '%s'", $parent_normal_path));
    $item['plid'] = $plid;
  }
}
joehodsdon’s picture

The same approach can be used directly in hook_menu:

function hook_menu() {
  $parent_normal_path = 'node/6';
  $plid = db_result(db_query("SELECT mlid FROM {menu_links} WHERE link_path = '%s'", $parent_normal_path));

  $items = array();
  $items['member/pick'] = array(
    'title' => 'Member Pick',
    'menu_name' => 'menu-main-menu',
    'page callback' => 'member_pick_page',
    'access callback' => TRUE,
    'type' => MENU_NORMAL_ITEM,
    'plid' => $plid,
  );
  return $items;
}