You are here

function clone_node_clone_menu_link in Node clone 7

Same name and namespace in other branches
  1. 6 clone.pages.inc \clone_node_clone_menu_link()

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 clone_node_clone_menu_link()
_clone_node_prepare in ./clone.pages.inc
Prepares a node to be cloned.

File

./clone.pages.inc, line 135
Additional functions for Node_Clone module.

Code

function clone_node_clone_menu_link($node) {
  if (variable_get('clone_menu_links', FALSE) && 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;
}