Menu system: Default tab behavior

kkaefer - February 4, 2007 - 14:50
Project:Drupal
Version:6.x-dev
Component:menu system
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

With the new menu system, tabs changed radically in how they work behind the façade. However, I noticed that the default tab doesn’t point to it’s parent.

Let’s take an example: on user/1, the (active) ‘view’ tab points to user/1/view rather than to user/1. The same happens all around Drupal, for example in admin/content/types vs. admin/content/types/list. This leads to several problems:

  • Duplicate content: user/1 and user/1/view share the exact same content, even though they have different URLs.
  • Help module breaks: If you specify a help text for admin/content/types (there is in fact one), it won’t show up on admin/content/types/list, even though it’s the same content.
  • user/1 and user/1/view don’t have the same page titles: While user/1 shows the user name as page title, user/1/view has the title ‘View’. That means, page titles do now change from tab to tab rather than staying the same on one tab level. This is not the intended behavior: Tabs are usually displayed below the page title and are therefore “sub pages” of that title.

#1

kkaefer - February 4, 2007 - 14:53

Ok, this doesn’t happen for user/1, because the page title is set somewhere else and not taken from the menu system. However, admin/content/types vs. admin/content/types/list is a good example.

#2

chx - March 26, 2007 - 07:19
Status:active» needs review

This patch restores all behaviour mostly -- if you have an object for the default tab then it points to itself otherwise it's the parent.

AttachmentSize
menu_86.patch 4.1 KB

#3

kkaefer - March 26, 2007 - 14:18
Status:needs review» needs work

There are some glitches:

When you’re on a non-default tab:

  • …the default tab still points to the old URL (admin/content/types/list instead of admin/content/types)
  • …the non-default tab points to the default tab without the link_item appendix (e.g. admin/content/types instead of admin/content/types/add)

#4

ChrisKennedy - June 4, 2007 - 00:11
Status:needs work» reviewed & tested by the community

Here is a patch from chx via IRC - I tested it and it correctly fixes default tab behavior. I had noticed some problems that popped up within statistics.module (http://drupal.org/node/143081).

AttachmentSize
menu_defaulttask.patch 2.56 KB

#5

Dries - June 4, 2007 - 07:34
Status:reviewed & tested by the community» needs work

Can we add some code comments please? Thanks! :)

#6

pwolanin - June 4, 2007 - 23:11

I thought I fixed the problem with the Help module in an earlier patch?

(from menu.inc - look at the last line)

function menu_get_active_help() {

  $output = '';
  $item = menu_get_item();

  if (!$item || !$item['access']) {
    // Don't return help text for areas the user cannot access.
    return;
  }
  $path = ($item['type'] == MENU_DEFAULT_LOCAL_TASK) ? $item['tab_parent'] : $item['path'];

#7

ChrisKennedy - June 9, 2007 - 22:03

@Peter - this patch fixes the default tab link, not the help.

#8

pwolanin - June 10, 2007 - 14:52

I need to work through this more, but I don't think this code is going to work at depths below the first level of local tasks.

#9

pwolanin - June 10, 2007 - 17:41
Status:needs work» needs review

this isn't maximally efficient, but seems to work. I'll post some additional code to use for testing as well.

AttachmentSize
local_tasks_path_1.patch 2.66 KB

#10

pwolanin - June 10, 2007 - 17:52

ok, trying to get around the upload restrictions ;-)

rename the attached file to tabtest.zip and unzip it. Inside is a small test module and a replacement for the page.tpl.php of garland. This version just shows tabs at depths below 0 and 1.

Substitute the page.tpl.php and enable the module. Visit /tabtest and /tabtest/6 (or any arg)

AttachmentSize
tabtest.zip_.doc 2.35 KB

#11

pwolanin - June 10, 2007 - 20:25

with additional/corrected code comments.

AttachmentSize
local_tasks_path_2.patch 3.6 KB

#12

chx - June 13, 2007 - 09:39

Steven reviewed the patch and complained that default tasks within default tasks does not point high enough. That's solved by a nice empty for loop which climbs up until it finds a non default local task. Also, he mentioned that we should not show single tabs. Fixed, too.

AttachmentSize
local_tasks_path.patch 3.97 KB

#13

pwolanin - June 13, 2007 - 15:31

Since this patch stores the full item in the $items array, it seems the $tab_parent array is unused and can be eliminated.

+        $tab_parent[$item['path']] = $item['tab_parent'];

#14

pwolanin - June 17, 2007 - 02:02

using chx's logic to find the right href for local tasks, but rewrote the code and re-tested.

AttachmentSize
local_tasks_path_3.patch 4.15 KB

#15

flk - June 17, 2007 - 12:07
Status:needs review» reviewed & tested by the community

yeap this patch works fine ;)

tested it on both blocks and the little tab module you gave...works great.

#16

Gábor Hojtsy - June 17, 2007 - 14:35

All seems to be fine here. How does this affect the help use case and pwolanin's workaround in particular? It seems this patch should remove that.

#17

Gábor Hojtsy - June 17, 2007 - 14:56
Status:reviewed & tested by the community» fixed

Discussed the issue with chx on IRC, and the help issue is different, will be addressed in another patch.
Done another review and it looks good, so committed.

#18

Anonymous - July 1, 2007 - 15:16
Status:fixed» closed
 
 

Drupal is a registered trademark of Dries Buytaert.