function node_clone_node_clone_menu_link in Node clone 8
Create a new menu link cloned from another node.
Returns NULL if no existing link, or links are not to be cloned.
1 call to node_clone_node_clone_menu_link()
- _node_clone_node_prepare in ./
node_clone.pages.inc - Prepares a node to be cloned.
File
- ./
node_clone.pages.inc, line 149 - Additional functions for Node_Clone module.
Code
function node_clone_node_clone_menu_link($node) {
if (\Drupal::config('node_clone.settings')
->get('node_clone_menu_links') && function_exists('menu_node_prepare')) {
// This will fetch the existing menu link if the node had one.
menu_node_prepare($node);
if (!empty($node->menu['mlid'])) {
$old_link = $node->menu;
$link['link_title'] = t('Clone of !title', array(
'!title' => $old_link['link_title'],
));
$link['plid'] = $old_link['plid'];
$link['menu_name'] = $old_link['menu_name'];
$link['weight'] = $old_link['weight'];
$link['module'] = $old_link['module'];
// Use the value -1 because it casts to boolean TRUE in function
// menu_form_node_form_alter() in menu.module so the node form checkbox
// is selected, but in function menu_link_save() no existing link will
// match.
$link['mlid'] = -1;
$link['has_children'] = 0;
$link['hidden'] = $old_link['hidden'];
$link['customized'] = $old_link['customized'];
$link['options'] = $old_link['options'];
$link['expanded'] = $old_link['expanded'];
$link['description'] = $old_link['description'];
$link['language'] = isset($old_link['language']) ? $old_link['language'] : NULL;
// This is needed to get the link saved in function menu_node_save() when
// using the save-edit method.
$link['enabled'] = TRUE;
return $link;
}
}
return NULL;
}