3

I have a series of pages created through Views, all the view pages are relative to one piece of content. The content paths I have created are

 - mycontent/[nid]/overview
 - mycontent/[nid]/members
 - mycontent/[nid]/content

Not that whats inside the view is particularly important but in this example, the first one shows the basic information about the node, the second shows everyone who is referenced by an entity reference, and the third shows all nodes connected by an entity reference.

I have created a new menu called 'mycontent-submenu' which I want to fill with links of:

 - Overview
 - Members
 - Content

Obviously you cannot use the Views module's menu ability to provide this as a menu item (unless you want to use it as a tab, which unfortunately I don't). In a more general term, the first question would be, how can I put these pages into a proper Menu (ie, not a tab)?

I already know of 1 way in which to solve this, which is to use Menu Views, with that I made a view for each of the Overview, Members and Content page, set the limit to 1, applied a 'null' contextual filter, and forced the output of the view to be re-written as 'mycontent/!1/overview'. Which works, but its a little hacky for my liking, plus you're querying the database a lot, I've done it before and it ended up increase the page load time if you have multiple menu items.

What I want to try to do right now is try to make a menu item programmatically in my own custom module, but I don't know what I'm doing wrong. My current code is:

function mymodule_menu() {
  $items['mycontent/%nid/overview'] = array(
    'title' => 'Overview',
    'description' => 'View the item',
    'menu_name' => 'menu-mycontent-submenu',
    'page callback' => views_page('individual_item', 'item_overview'),
    'page arguments' => array(1),
    'access callback' => TRUE,
    'expanded' => TRUE,
  );

  $items['mycontent/%nid/members'] = array(
    'title' => 'Members',
    'description' => 'Item members',
    'menu_name' => 'menu-mycontent-submenu',
    'page callback' => views_page('individual_item', 'item_members'),
    'page arguments' => array(1),
    'access callback' => TRUE,
    'expanded' => TRUE,
  );

  $items['mycontent/%nid/content'] = array(
    'title' => 'Content',
    'description' => 'All the Content for this item',
    'menu_name' => 'menu-mycontent-submenu',
    'page callback' => views_page('individual_item', 'item_content'),
    'page arguments' => array(1),
    'access callback' => TRUE,
    'expanded' => TRUE,
  );
}

As far as I can tell, I've researched how you call a view within a page callback, which is views_page, and I've declared that I want my links to go into the right menu structure, but nothing actually appears. Is this block of code correct for what I want to do.

2

you need to return $items at the end

2

You are missing the return in your function:

function mymodule_menu() {

  $items['mycontent/%nid/overview'] = array(
    'title' => 'Overview',
    'description' => 'View the item',
    'menu_name' => 'menu-mycontent-submenu',
    'page callback' => views_page('individual_item', 'item_overview'),
    'page arguments' => array(1),
    'access callback' => TRUE,
    'expanded' => TRUE,
  );

  $items['mycontent/%nid/members'] = array(
    'title' => 'Members',
    'description' => 'Item members',
    'menu_name' => 'menu-mycontent-submenu',
    'page callback' => views_page('individual_item', 'item_members'),
    'page arguments' => array(1),
    'access callback' => TRUE,
    'expanded' => TRUE,
  );

  $items['mycontent/%nid/content'] = array(
    'title' => 'Content',
    'description' => 'All the Content for this item',
    'menu_name' => 'menu-mycontent-submenu',
    'page callback' => views_page('individual_item', 'item_content'),
    'page arguments' => array(1),
    'access callback' => TRUE,
    'expanded' => TRUE,
  );

  return $items; // <--- WHAT YOU ARE MISSING

}
  • Better answer for providing code sample. Thx! – emc Mar 16 '15 at 19:21

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.