If we alter our hook_menu implementation to add menu_name, the link is not updated

Comments

pwolanin’s picture

Status: Active » Needs review
StatusFileSize
new1.15 KB

patch - minimally tested

moshe weitzman’s picture

Status: Needs review » Active

this is breaking an upcoming Views feature: #284893: Allow admin to place menu items into primary links or other menus.. i will review this soon.

moshe weitzman’s picture

Status: Active » Reviewed & tested by the community

I tested that this allows uncustomized items to be moved to another menu and does not allow save for customized. This should backport to 6 after commit to HEAD.

moshe weitzman’s picture

Bump - this is a bug fix. Please commit and backport. chx has agreed with the patch as well.

dries’s picture

Status: Reviewed & tested by the community » Needs work

Subtle (or not so subtle) features or bugs like these are best committed along with a test case. If we break the behavior, we want to know this instantly.

greg.harvey’s picture

+1 this - I'm experiencing the issue with D6. Failing code looks like this:

function dev_menu() {
  $content_type = 'guide';
  $menu_name = 'guides';
  $result = db_query("SELECT nid, title FROM {node} WHERE type = '%s'", array($content_type));
  while($node = db_fetch_array($result)) {
    $this_node = node_load($node['nid']);
    $items[$menu_name.'/'.$node['nid']] = array(
      'title' => $node['title'],
      'page callback' => 'node_page_view',
      'page arguments' => array($this_node),
      'access callback' => 'node_access',
      'access arguments' => array('view', 1),
      'type' => MENU_NORMAL_ITEM,
      'menu_name' => $menu_name,
    );
  }
  return $items;
}

'menu_name' is ignored. Judging by the title of this issue, I guess it would've worked if I'd placed this code first time, but subsequent updates to 'menu_name' fail, but I didn't test for that. Just simply 'menu_name' is ignored in Drupal 6.4 with the above code.

I guess you could turn the above in to a test case by setting the $menu_name to something that exists and setting $content_type to 'page' (assuming you have some pages). Check the menu builds correctly, change $menu_name to something else, clear caches and see what happens. Old behaviour is "nothing - menu item stays where it is!"

moshe weitzman’s picture

Status: Needs work » Needs review
StatusFileSize
new842 bytes
new374 bytes
new174 bytes

Here is a set of test files that confirm that Peter's patch above is a successful bug fix and never shall we break it :)

These files are the start to a full suite of hook_menu() tests. These files belong in modules/simpletest/files. Remove the .txt extension. They don't belong with the existing menu tests since those tests the menu.module which is a GUI for menu.inc. These files are for non GUI functionality.

As mentioned before, Peters patch should be applied to D6 once this lands in HEAD.

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new3.92 KB

Here is a complete patch with new test and dummy module. The test fails in the absence of the patch to menu.inc, and succeeds after the test is applied.

The new test files will need cvs add, of course.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

chx and I both cringed at the $GLOBALS thing in there, which could possibly affect the environment running the tests, rather than the test environment. Marking CNW for now, but once the test is fixed up, this should be good to go according to chx, moshe, and earl. :)

pwolanin’s picture

Status: Needs work » Needs review
StatusFileSize
new4.12 KB

here's a re-wroked test uses a query string and the UI.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Works well and fixes the bug.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. Thanks, Peter!

moshe weitzman’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Reviewed & tested by the community

Changing to D6 for the bug fix. Please just commit the patch to menu.inc, not the test files.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to DRUPAL-6 as well. Thanks! :)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.