A Drupal view serving multiple tabs

Drupal's menu hierarchy is a big and complex beast. It acts as both the repository for registered menu callback handlers (and their associated permissions handlers) and as a way of building more mundane frontend menus for people to click round. It serves both static hierarchical side menus and also dynamic tabbed contextual menus: if you're on a user's profile page, there are "View" and "Edit" tabs, with "Account" and maybe "Profile" sub-tabs under "Edit"; yet this menu hierarchy doesn't exist in any real sense. This complexity, and this slight disconnect between all the various bits of menu.inc and menu.module, means that menu often gets exposed to other modules in a counter-intuitive way.

Say you've got a listing of content (using Views, naturally). You want this listing to sit at /posts . But you also want an advanced search to sit at /posts/advanced , and you need tabs across the top of the page. Should be easy, right? Create a view, put it on a menu path, in a menu, then create a second view and, oh, I don't know: put it as a menu tab? As a default menu tab? As a normal menu item under the menu item you just built? Or maybe build a page, and put that on the menu, then create two views as child menu tabs, or maybe one as the default menu tab, or....

After lots of fiddling, I realized you could take advantage of Views' ability to clone displays within a single view, to solve this fairly straightforwardly.

  1. Start off by building your "Default" display---the initial display a view gives you---so that it matches the field and filter criteria you want to sit at /posts . 
  2. Then create a "Page" display to handle the standard search. Set it to be a normal menu item, at path /posts . Check it's on the menu hierarchy.
  3. Create a second "Page" display with exactly the same configuration. Under "Page settings", give it the path '/posts/default' and make it a "Default menu tab" with the parent as "Already exists."
  4. You now have a tab to handle your default, non-advanced search, and a menu hierarchy entry to tie it to. Further tabs should now be straightforward.
  5. Your advanced search can now be created as a third "Page" display. As with #3 above, give it a path '/posts/advanced' and make it a "Default menu tab" with the parent as "Already exists."
The trick here is to remember that two tabs need four view displays: the view's core display; a display that never gets seen but sits on the menu hierarchy; and two displays for the standard and advanced tabs. There are other ways to do this with fewer view displays, but only by having e.g. a module handle the main menu entry or one of the tabs. Ultimately two tabs need three menu handlers, and three menu handlers needs a four-display view.