I am creating a set of nodes in an installation profile. When I try to create menu links for them in the same PROFILE_NAME.install, the links don't get created.
I have also tried creating the menus links in a separate module, and using hook_update_N()
to enable them, but that also does not work.
When I uninstall the module and reactivate it, it creates correctly my menu's links correctly.
I tried to use hook_install_tasks()
and put it in MYPROFILE_NAME.profile or MYPROFILE_NAME.install, but this also doesn't work.
How can I create menu links for nodes created as part of an installation profile?
My code for creating the nodes in MY_PROFILE_NAME.install is:
// creation of my nodes (same content for all)
$nodi = array(
// i have other 14 nodes
'title' => array('Home'),
// i have other 14 paths for the nodes
'path' => array('home'),
);
$titoli = array();
$titoli = $nodi['title'];
$percorsi = array();
$percorsi = $nodi['path'];
//CREAZIONI DEL CONTENUTO PROGRAMMATICAMENTE
for($i = 0; $i< count($titoli); $i++){
$testo_body = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec feugiat velit eget metus placerat,varius eros facilisis. Aenean aliquam imperdiet nisl ut dapibus...';
$node = new stdClass(); // nuovo oggetto nodo
$lingua = 'it';
$node->type = "page"; //
$node->title = $titoli[$i];
$node->language = $lingua;
$node->path = array('alias' => $percorsi[$i]); // i think here is the problem !!!
$node->uid = 1; // admin
$node->status = 1;
// Body field
$body_field_info = field_info_field('body');
if (field_is_translatable('node', $body_field_info)) {
$body_lingua = field_valid_language($lingua);
}else{
$body_lingua = LANGUAGE_NONE;
}
$node->body[$body_lingua][0]['value'] = $testo_body;
$node->body[$body_lingua][0]['summary'] = 'text...';
$node->body[$body_lingua][0]['format'] = 'full_html';
$node = node_submit($node); // Prepare node for a submit
node_save($node); // After this call we'll get a nid
And my code for creating the menu links is:
// Create a Home link in the main menu.
$path = drupal_lookup_path('source', 'home');
$item = array(
'link_path' => $path,
'router_path' => $path,
'link_title' => st('Home'),
'menu_name' => 'main-menu',
'weight' => -50,
'customized' => 1,
'plid' => 0, // Parent menu item, 0 if menu item is on top level
);
menu_link_save($item);
menu_rebuild();
Update 2
The menus are created in the menu_links table but with empty link_path so i can't get the nid created nodes. I treid also to override the install_finished() and put my function for creating menus in .install or in .profile files, but it's the same. Any ideas?