menu_node_prepare

Versions
7
menu_node_prepare($node)

Implements hook_node_prepare().

Code

modules/menu/menu.module, line 509

<?php
function menu_node_prepare($node) {
  if (empty($node->menu)) {
    // Prepare the node for the edit form so that $node->menu always exists.
    $menu_name = variable_get('menu_default_node_menu', 'navigation');
    $item = array();
    if (isset($node->nid)) {
      // Give priority to the default menu
      $mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", 0, 1, array(
        ':path' => 'node/' . $node->nid,
        ':menu_name' => $menu_name,
      ))->fetchField();
      // Check all menus if a link does not exist in the default menu.
      if (!$mlid) {
        $mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' ORDER BY mlid ASC", 0, 1, array(
          ':path' => 'node/' . $node->nid,
        ))->fetchField();
      }
      if ($mlid) {
        $item = menu_link_load($mlid);
      }
    }
    // Set default values.
    $node->menu = $item + array(
      'link_title' => '',
      'mlid' => 0,
      'plid' => 0,
      'menu_name' => $menu_name,
      'weight' => 0,
      'options' => array(),
      'module' => 'menu',
      'expanded' => 0,
      'hidden' => 0,
      'has_children' => 0,
      'customized' => 0,
    );
  }
  // Find the depth limit for the parent select.
  if (!isset($node->menu['parent_depth_limit'])) {
    $node->menu['parent_depth_limit'] = _menu_parent_depth_limit($node->menu);
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.