- Patch #761648 by lyricnz, andypost, ksenzee, Jody Lynn, Gábor Hojtsy, Damien Tournoud, Shawn DeArmond, David_Rothstein: menu items disappear after upgrade or manual menu entry.
parent
02494f9679
commit
3ca907cb35
|
@ -540,18 +540,23 @@ function menu_node_delete($node) {
|
|||
function menu_node_prepare($node) {
|
||||
if (empty($node->menu)) {
|
||||
// Prepare the node for the edit form so that $node->menu always exists.
|
||||
$menu_name = variable_get('menu_parent_' . $node->type, 'main-menu:0');
|
||||
$menu_name = strtok(variable_get('menu_parent_' . $node->type, 'main-menu:0'), ':');
|
||||
$item = array();
|
||||
if (isset($node->nid)) {
|
||||
$mlid = FALSE;
|
||||
// Give priority to the default menu
|
||||
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", 0, 1, array(
|
||||
':path' => 'node/' . $node->nid,
|
||||
':menu_name' => $menu_name,
|
||||
))->fetchField();
|
||||
// Check all menus if a link does not exist in the default menu.
|
||||
if (!$mlid) {
|
||||
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' ORDER BY mlid ASC", 0, 1, array(
|
||||
$type_menus = variable_get('menu_options_' . $node->type, array('main-menu' => 'main-menu'));
|
||||
if (in_array($menu_name, $type_menus)) {
|
||||
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", 0, 1, array(
|
||||
':path' => 'node/' . $node->nid,
|
||||
':menu_name' => $menu_name,
|
||||
))->fetchField();
|
||||
}
|
||||
// Check all allowed menus if a link does not exist in the default menu.
|
||||
if (!$mlid && !empty($type_menus)) {
|
||||
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' AND menu_name IN (:type_menus) ORDER BY mlid ASC", 0, 1, array(
|
||||
':path' => 'node/' . $node->nid,
|
||||
':type_menus' => array_values($type_menus),
|
||||
))->fetchField();
|
||||
}
|
||||
if ($mlid) {
|
||||
|
|
|
@ -664,5 +664,21 @@ class MenuNodeTestCase extends DrupalWebTestCase {
|
|||
// Assert that there is no link for the node.
|
||||
$this->drupalGet('');
|
||||
$this->assertNoLink($node_title);
|
||||
|
||||
// Add a menu link to the Management menu.
|
||||
$item = array(
|
||||
'link_path' => 'node/' . $node->nid,
|
||||
'link_title' => $this->randomName(16),
|
||||
'menu_name' => 'management',
|
||||
);
|
||||
menu_link_save($item);
|
||||
|
||||
// Assert that disabled Management menu is not shown on the node/$nid/edit page.
|
||||
$this->drupalGet('node/' . $node->nid . '/edit');
|
||||
$this->assertText('Provide a menu link', t('Link in not allowed menu not shown in node edit form'));
|
||||
// Assert that the link is still in the management menu after save.
|
||||
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
|
||||
$link = menu_link_load($item['mlid']);
|
||||
$this->assertTrue($link, t('Link in not allowed menu still exists after saving node'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue