I want to change the parent of a menu tree on a node update. I’m using the module named “rules” to access the update event and I have this code as follows:
if ($node->taxonomy[1] == "1") {
$plid = 440;
} else if ($node->taxonomy[1] == "2") {
$plid = 379;
}
if($plid) {
db_query("UPDATE {menu_links} SET plid='".$plid."', p1='".$plid."' WHERE link_path='"."node/".$node->nid."'");
}
The problem is that this $node which is updated also has some child menu items under it, in the primary menu and when I update the node to change the parent, its children just end up one level higher and don’t get moved with current menu item. Is there an easy way to move a whole menu tree from one parent menu item to another?
I want this,
–parent1
—child1
—sub-child1
—sub-child2
–parent2
to be this:
–parent1
–parent2
—child1
—sub-child1
—sub-child2
Can you help me? Is there a Drupal-way of doing this? =)
I know that this code makes a lot of assumptions but I need it just for one specific case
I figured it out by experimenting with the API:
Just needed to figure out that I didn’t have to deal with those “p0” to “p8” when saving the new menu item. Drupal seems to automatically move the children. By the way, I could use a more reliable way of getting mlid of nodes menu item.