Home > php教程 > PHP源码 > body text

drupal7 - menu下所有node复制一份

PHP中文网
Release: 2016-05-25 17:01:52
Original
1137 people have browsed it


$menu_name = 'menu-main-menu-us';

function _node_setup($node) {
	// domain option set to United States
	$node->domain_site = FALSE;
	$node->domains = array(2 => 2);
	$node->subdomains = array(0 => 'United States');
	return $node;
}

$menus = menu_tree_all_data($menu_name);

function _menu_recursion($menus) {
	foreach($menus as $menu) {
		if(preg_match("/node\\/(\\d+)/i", $menu['link']['link_path'], $matches)) {
			$node_id = $matches[1];
			// clone node
			$oNode = node_load($node_id);
			$node = clone $oNode;
			$node->nid = NULL;
			$node->vid = NULL;
			$node->tnid = NULL;
			$node = _node_setup($node);
			node_save($node);

			// reset menu
			$menu_obj = menu_link_load($menu['link']['mlid']);
			$menu_obj['link_path'] = 'node/'.$node->nid;
			$menu_obj['href'] = 'node/'.$node->nid;
			menu_link_save($menu_obj);
		}
		if(!empty($menu['below'])) {
			_menu_recursion($menu['below']);
		}
	}
}

_menu_recursion($menus);
Copy after login

                   

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template