hello,

on d6 i used following code to post into a php enabled node, this is a "1 time usage snipped", it creates pages and menu from 1 array.

<?php
$insert[] = array("menu" => "primary-links", "path" => "MY-MENU", "link_title" => "My-Menutitle");
$insert[] = array("menu" => "primary-links", "path" => "MY-MENU/SUBMENU", "link_title" => "My-SubMenutitle");
$insert[] = array("menu" => "primary-links", "path" => "MY-MENU/SUBMENU2", "link_title" => "My-SubMenutitle2");

foreach($insert AS $line){

	$node = new StdClass;
	$node->type = 'page'; //Inhaltstyp
	$node->body = 'Platzhalterseite';
	$node->title = $line['link_title'].' - Platzhalter';
	$node->uid = 1;
	$node->status = 1;
	$node->active = 1;
	$node->promote = 1;
	$node->path = $line['path'];
	$node_id = node_save($node);

	$menu = array(
	'link_title' => $line['link_title'],
	'router_path' => $line['path'],
	'link_path' => 'node/'.$node->nid,
	'mlid' => 0,
	'plid' => 0,
	'menu_name' => $line['menu']
	);

	menu_link_save($menu);

	unset($node);
	unset($menu);
}
?>

The code above pasted into a D7 node will result in:
Fatal error: Unsupported operand types in /www/htdocs/space/includes/path.inc on line 435

so any suggestion for modification, please?

this is not a module, it's only a 1 time snipped, 1 usage, remove node.

thank you,

Andreas

Comments

gagarine’s picture

Why you don't add the menu on the node object before saving? It should work with D7 too....

$node->menu['link_title'] = "Menu Item Name";
$node->menu['menu_name'] = 'custom-menu-name';
$node->menu['plid'] = 0;
$node->menu['weight'] = 1;

https://interface-network.com - Interface Network is an action and research technology governance agency.