You are here

function menu_node_import_get_parent_from_path in Node import 6

Given an url alias, look to see if a menu item already exists

1 call to menu_node_import_get_parent_from_path()
menu_node_import_values_alter in supported/menu.inc
Implementation of hook_node_import_values_alter().

File

supported/menu.inc, line 141
Support file for the core menu module.

Code

function menu_node_import_get_parent_from_path($parent_path) {
  if (!$parent_path) {
    return NULL;
  }

  // look up appropriate menu item identifier
  drupal_lookup_path('wipe');

  // batch jobbing this needs to flush the cache
  if ($parent_system_path = drupal_get_normal_path($parent_path)) {

    // menu doesn't provide a get-menu item by name. Do it myself. This also helps avoid menu caching issues.
    $result = db_query("SELECT mlid,plid,menu_name FROM {menu_links} WHERE link_path = '%s' LIMIT 1", $parent_system_path);
    while ($menu_item = db_fetch_array($result)) {
      $parent = $menu_item['menu_name'] . ':' . $menu_item['mlid'];
    }

    // However later processes (node_save validate) are not up to date with the just-created menu items
    // and don't believe the parent exists :-(
    // Do I really have to:
    // menu_rebuild(); // each time?
    // This slows everything down HEAPS
    // so really should check if it's needed first
    menu_rebuild();

    // menu.module appears to provide an out? - beware - this setting messes up menu selector functions

    #variable_set('menu_override_parent_selector', TRUE);
    return $parent;
  }
}