I am developing a script that builds nodes programatically based on some data held in a separate database table. It's working well, nodes are created on the flyand added to a menu of my choosing with data applied to CCKs. One part of the script will create the CCKs if they don't exist already, but I need to do the same with menus. Is there a function that will look to see if a menu exists and another that will create a menu? The reason for this is so that once I have perfected it I can hand it to somebody else to do a quick install by running the script once.

Comments

You can create menu items

You can create menu items fairly easily with menu_link_save but I think menu_save wasn't added until D7. There is an example on how to create menus programmattically using drupal_execute here:

http://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_link_save/6#comment-6359

~Chad

Thanks for the response -

Thanks for the response - that worked a treat.

One other thing that is bugging me is getting the right hierarchy for mu page in the menu when using save_node(). I have this:

<?php
$node
= new stdClass();
   
$node->title = $title;
   
$node->body = $content;
   
$node->type = 'page';   // story or page
   
$node->created = $time;
   
$node->changed = $time;
   
$node->status = 1;
   
$node->promote = 1;
   
$node->sticky = 0;
   
$node->format = 3;
   
$node->uid = 1;
   
$node->name = $title;
   
$node->language = 'en';
   
$node->taxonomy = array(2,3,1);
   
$node->menu = array(
           
'enabled' => 1,
           
'mlid' => 0,
           
'module' => 'menu',
           
'hidden' => 0,
           
'has_children' => 0,
           
'customized' => 0,
           
'options' => array(),
           
'expanded' => 0,
           
'parent_depth_limit' => 4,
           
'link_title' => $title,
           
'description' => '',
           
'parent' => $menu.':0',
           
'weight' => '-10',
           
'plid' => '0',
           
'menu_name' => $menu
       
);

node_save($node);
?>

They all appear in the correct menu at the root, as expected. How do I go about moving node456 under node123? I have tried changing plid but is doesn't seem to work. I have tried many things, but I never get the response I am expecting. I have even tried doing a sql statement instead but I must be getting it wrong as the node doesn't move exactly where I expect it to.

If there is a separate bootstrap function such as move_node() I can use that because I know the $node->nid of the node just inserted and the parent of the node it needs to move to is saved in an array.

plid

You need to set plid
menu_name:$plid
plid => $plid

<?php
'parent' => $menu.':0',
'plid' => '0',
?>