You are here

function node_export_get_menu in Node export 6.2

Same name and namespace in other branches
  1. 6.3 node_export.module \node_export_get_menu()
  2. 7.3 node_export.module \node_export_get_menu()

Create a new menu entry with title, parent and weight exported from another nodes menu. Returns NULL if the node has no menu title.

1 call to node_export_get_menu()
node_export_node_export in ./node_export.module
Exports a node - populate a node code form set $return_code to TRUE to not return form but the code instead. set $format to some string if encoding should be handled by some module that will recognise the string.

File

./node_export.module, line 957
The Node Export module.

Code

function node_export_get_menu($node) {

  // This will fetch the existing menu item if the node had one.
  node_invoke_nodeapi($node, 'prepare');

  // Only keep the values we care about.
  if (!empty($node->menu)) {

    // Store a copy of the old menu
    $old_menu = $node->menu;

    // Now fetch the defaults for a new menu entry.
    $node = NULL;
    node_invoke_nodeapi($node, 'prepare');

    // Make a list of values to attempt to copy.
    $menu_fields = array(
      'link_title',
      'plid',
      'menu_name',
      'weight',
      // These should import properly always.
      'hidden',
      'expanded',
      'has_children',
    );

    // Copy those fields from the old menu over the new menu defaults.
    foreach ($menu_fields as $menu_field) {
      $node->menu[$menu_field] = $old_menu[$menu_field];
    }

    // Return the menu.
    return $node->menu;
  }
}