Menu items do not inherit their parent's load arguments

Alan D. - October 4, 2008 - 05:52
Project:Drupal
Version:6.x-dev
Component:menu system
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review
Description

I just noticed some errors when using some local task menu items with extra load arguments defined. After some investigation, I found that these are generated independently of the parent menu items based on the items "load arguments" and the items defined path.

The attached patch adds a check to allow the menu items to inherit their parents arguments:

The error was generated by the following menu declarations:

<?php
  $items
['projects/%project/job/%job'] = array(
   
'title callback' => 'jm_page_title',
   
'title arguments' => array(3),
   
'load arguments' => array('%map', '%index'),
   
'page callback' => 'jm_page_content',
   
'page arguments' => array('job', 1, 3),
   
'access arguments' => array('access job management system'),
   
'type' => MENU_NORMAL_ITEM,
  );
 
$items['projects/%project/job/%job/view'] = array(
   
'title' => 'View job',
   
'type' => MENU_DEFAULT_LOCAL_TASK,
//    this would prevent the error
//    'load arguments' => array('%map', '%index'),
   
'weight' => -10,
  );

// and one of the load callbacks
function job_load($nid, $map, $index) {
 
$project = $map[1];
  if (
$node = node_load(array('nid' => $nid))) {
    if (
$node->status && $node->type == 'job' && $project->nid = $node->field_project[0]['nid'] && node_access('view', $node)) {
      return
$node;
    }
  }
  return
FALSE;
}

?>

Alan Davison
www.caignwebs.com.au

#1

Alan D. - October 4, 2008 - 06:21
Title:Local task menu items do not inherit their parents load arguments » Menu items do not inherit their parents load arguments

As I go deeper into this, I've discovered that it is a general menu issue, not just for local task. Updated the patch to reflect this

AttachmentSize
menu-d6-dev.patch 1.31 KB

#2

Alan D. - October 6, 2008 - 00:18
Priority:normal» critical
Status:active» needs review

This can lead to some strange bugs when there is a dependency on the load argument. Bumping to critical.

#3

keith.smith - October 6, 2008 - 00:55
Title:Menu items do not inherit their parents load arguments » Menu items do not inherit their parent's load arguments
Status:needs review» needs work

On a quick code-style review, code comments should begin with a capital letter and end in a period.

#4

Alan D. - October 6, 2008 - 02:37
Status:needs work» needs review

I have fixed the code comments.

AttachmentSize
menu-d6-dev_0.patch 1.39 KB
 
 

Drupal is a registered trademark of Dries Buytaert.