Rule: Create New Menu Item(top-level parent, main menu) on node save.
Hello,
I was wondering if someone could assist. I can not seem to get the php code working on this and do not see an option to "set menu item" as an action. I need a menu item set, but the path would be the node title(yoursite/foo), foo being the title of the node of Type Foo. The path alias is already set in a feature with path auto alias included, but it is my understanding that the 'link_path' must be defined. What I really need is the auto creation of the menu item with some sensible default that doesn't give it a weight that sets it before the frontpage/home, but still allows manual menu reordering without overriding the feature(including the rule).
I have this as the code(I am not a coder(be gentle:), got this off a blog post for child menu items with an existing parent and tried change it for a top-level parent menu item).
$item = array(
'menu_name' => 'main-menu',
'link_path' => . $node->title ,
'link_title' => $node->title,
'mlid' => 0,
'plid' => 0
);
menu_link_save($item);
menu_cache_clear_all()Any help would be a blessing. Thanks so much,
Jen

Comments
Copy from Devel information
I am sorry to say that I don't (yet) know any way of setting menu items for nodes automatically without adding some custom code. :-(
I think you need to set the internal path in the link_path. That means that you need "node/1" rather than "foo". If the path alias is in place, then the alias will be used when actually rendering the link – but the internal path will be stored.
Here is some more information on what the $item may contain, such as weights for sorting the menu items: http://api.drupal.org/api/drupal/includes!menu.inc/function/menu_link_save/7
Best of luck,
//Johan Falk, Sweden
thanks!
Thanks so much, you're right on, thank you for the input. I got it working now:). I also needed to add menu_rebuild() since it is a new menu item and I think I was missing a ; at the last line. Again, I ''m not a coder so I am just getting used to checking syntax(other than css). Do you think I would still need menu_cache_clear_all(), I didn't think I would since it just did a rebuild, so there's nothing in the cache correct? Only thing is to work on the weight thing which is adding 'weight' =>, but I am still not certain how that will work with features if I want users to be able to reorder the menu items of all the features if they like. I am assuming that if a user reordered it would cause an override, since the weight value would be set in stone. Anxiously waiting on Features Override 7.x-2.0 with some fixes to the dev:) It is always well worth the wait, and I am always so appreciative to developers for all the hard work and making it freely available to the community. Thanks again! -Jen
$item = array(
'menu_name' => 'main-menu',
'link_path' => 'node/' . $node->nid,
'link_title' => $node->title
);
menu_link_save($item);
menu_rebuild();
menu_cache_clear_all();