0

I'm using hook menu here for the first time as token menu doesn't seem to be doing what I need.

In the end, I need a menu that will use a wildcard and load a view based on that wildcard. I have the views working, now working on the menu.

I have a "directory" structure like so:

  • committee/committee-name/charter
  • committee/committee-name/roster
  • etc...

So I am using hook menu like so:

$items['committee'] = array(
        'title' => 'Committee Page',
        'page callback' => 'committeemenu_mymenu_page_callback',
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );  

    $items['committee/%/roster'] = array(
        'title' => 'Roster',
        'page callback' => 'committeemenu_mymenu_page_callback',
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );  

    $items['committee/%/charter'] = array(
        'title' => 'Charter',
        'page callback' => 'committeemenu_mymenu_page_callback',
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );  

Committee shows on my menu, but Roster and Charter don't. I am not sure why not? If I give a wildcard, committee/%, to committee for example, I get no menu item. So is this a wildcard issue? should I be able to use a wildcard here? I am going to pull in a view based on wildcard and charter/roster content types.

1

See hook_menu for reference under using Wildcards but you need to tell your menu which page arguments are going to be passed into your function:

$items['committee'] = array(
        'title' => 'Committee Page',
        'page callback' => 'committeemenu_mymenu_page_callback',
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );  

    $items['committee/%/roster'] = array(
        'title' => 'Roster',
        'page callback' => 'committeemenu_mymenu_page_callback',
        'page arguments' => array(1),
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );  

    $items['committee/%/charter'] = array(
        'title' => 'Charter',
        'page callback' => 'committeemenu_mymenu_page_callback',
        'page arguments' => array(1),
        'access callback' => TRUE,
        'type' => MENU_NORMAL_ITEM,
    );  

In this case array(1) would be the second positiong (as array(0) would be the first) if your wildcard resided in committee/charter/% it would be array(2).

I do not believe your items will be showing in the menu because there are wild cards, you would have to do that in your local tasks instead as the menu would not have any idea.

  • So I would create the menu items and then alter them? – jasonflaherty Jul 23 '14 at 17:14
  • they don't show you are correct... – jasonflaherty Jul 23 '14 at 17:14
  • I do not believe they are going to show up in the menu when you are using a wildcard as MENU_NORMAL_ITEM is available in the menu structure so it is not going to know what % is dynamically in the menu structure. So basically you are left with either adding it in actions menu or tabs, or manually adding it per wildcard. – chadpeppers Jul 23 '14 at 17:19
  • Another option is to try to define your own wildcard loader which may work. See drupal.org/node/209056 – chadpeppers Jul 23 '14 at 17:24
  • thanks for the comments, I'll check out the wildcard loader. I would in the end just like a menu that has wildcards that will load based on whatever page the user is on. – jasonflaherty Jul 23 '14 at 17:34
0

From what I understand, the only way to do this dynamic menu idea based on URL string / Node info is by using something like Menu Token. However, it didn't work well for my needs. Drupal Caches your menus, and since I am requiring something dynamic a menu wasn't going to work (unless someone else can give me some ideas).

The solution I am using is to create a new block and use PHP and/or JavaScript to create the menu. I did a quick mock up in JS and retrieved the URL and then inserted which committee I was on into the url and made the menu items.

<ul><li><a href="committees/' + getSecondPart(u) + '/charter">Charter</a></li><li><a href="committees/' + getSecondPart(u) + '/roster">Roster</a></li></ul>

getSecondPart(str) just returns the name of the committee in my case (committees/name/charter). You can break up a string however you'd like as long as it is consistent, which is possible with Views use.

Anyhow... I'll be moving this into php and a hook_block custom module which will hopefully solve all my woes... hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.