- Patch #401922 by Damien Tournoud: fixed parent link detection.

merge-requests/26/head
Dries Buytaert 2009-03-14 20:56:06 +00:00
parent 3a7047c670
commit 56e1c5d106
3 changed files with 31 additions and 4 deletions

View File

@ -2063,16 +2063,17 @@ function menu_link_save(&$item) {
// If not derived from a router item, we respect the specified menu name.
$query->condition('menu_name', $item['menu_name']);
}
// Find the parent - it must be unique.
$parent_path = $item['link_path'];
do {
$parent = FALSE;
$parent_path = substr($parent_path, 0, strrpos($parent_path, '/'));
$query->condition('link_path', $parent_path);
$query_cnt = $query;
$new_query = clone $query;
$new_query->condition('link_path', $parent_path);
// Only valid if we get a unique result.
if ($query_cnt->countQuery()->execute()->fetchField() == 1) {
$parent = $query->fields('menu_links')->execute()->fetchAssoc();
if ($new_query->countQuery()->execute()->fetchField() == 1) {
$parent = $new_query->fields('menu_links')->execute()->fetchAssoc();
}
} while ($parent === FALSE && $parent_path);
}

View File

@ -47,6 +47,18 @@ class MenuIncTestCase extends DrupalWebTestCase {
$name = db_result(db_query($sql));
$this->assertEqual($name, 'changed', t('Menu name was successfully changed after rebuild.'));
}
/**
* Tests for menu hiearchy.
*/
function testMenuHiearchy() {
$parent_link = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => 'menu-test/hierarchy/parent'))->fetchAssoc();
$child_link = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => 'menu-test/hierarchy/parent/child'))->fetchAssoc();
$unattached_child_link = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => 'menu-test/hierarchy/parent/child2/child'))->fetchAssoc();
$this->assertEqual($child_link['plid'], $parent_link['mlid'], t('The parent of a directly attached child is correct.'));
$this->assertEqual($unattached_child_link['plid'], $parent_link['mlid'], t('The parent of a non-directly attached child is correct.'));
}
}
/**

View File

@ -24,6 +24,20 @@ function menu_test_menu() {
'page callback' => 'menu_test_callback',
'access arguments' => array('access content'),
);
// Hierarchical tests.
$items['menu-test/hierarchy/parent'] = array(
'title' => 'Parent menu router',
'page callback' => 'node_page_default',
);
$items['menu-test/hierarchy/parent/child'] = array(
'title' => 'Child menu router',
'page callback' => 'node_page_default',
);
$items['menu-test/hierarchy/parent/child2/child'] = array(
'title' => 'Unattached subchild router',
'page callback' => 'node_page_default',
);
return $items;
}