Each time after pushing "Install" button at new module or theme install drupal report following error on blank screen:

Fatal error: Call to undefined function menu_get_ancestors() in /home3/ruspolei/public_html/sites/all/modules/subdomain/subdomain.module on line 636

Comments

abacs’s picture

i also have this problem, in csae of module update too

netikseo’s picture

Yep, have the same issue. But when I disable subdomain module I can install modules without this error. Still a bit annoying if I have to do it every time. Please fix it.

inventlogic’s picture

Title: Call to undefined function menu_get_ancestors() » Call to undefined function menu_get_ancestors()

In the subdomain.module file the function _subdomain_id_from_path on line 594 (approximately) is attempting to use functions and constants defined in the menu.inc include.

I think it is producing errors because the _subdomain_id_from_path is not a hook function so it cannot depend on automatic includes from the underlying main drupal functions the hook is calling.

I tried to fix this error by doing the following:

Edit the subdomain.module file and add after function _subdomain_id_from_path($type, $path) {
the following line: require_once('includes/menu.inc');

I think this works ok but I am not sure it is the correct Drupal way of accessing the menu.inc functions and constants.

The code from the function that is causing the problem is the following

    // Fallback on searching the menu system. We don't try this first since we want to try and avoid searching the DB.
    if (empty($id)) {
      $map = arg(NULL, $path);
      $parts = array_slice($map, 0, MENU_MAX_PARTS);
      $ancestors = menu_get_ancestors($parts);
      $router_item = FALSE;

      // See if we've seen a matching menu router item already for one of the ancestors
      foreach ($ancestors as $ancestor) {
        if (isset($router_items[$ancestor])) {
          $router_item = $router_items[$ancestor];
          break;
        }
      }

It seems to have been partly snagged from the menu_get_item function

 if (!isset($router_items[$path])) {
    // Rebuild if we know it's needed, or if the menu masks are missing which
    // occurs rarely, likely due to a race condition of multiple rebuilds.
    if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) {
      menu_rebuild();
    }
    $original_map = arg(NULL, $path);

    $parts = array_slice($original_map, 0, MENU_MAX_PARTS);
    $ancestors = menu_get_ancestors($parts);
    $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc();

So I suppose the question is can the value of the $router_item be gotten through standard Drupal hook functions?
Any help comments appreciated.

inventlogic’s picture

Status: Active » Closed (duplicate)

This is a duplicate of https://drupal.org/node/1326274

ionut.stan’s picture

#3 worked for me too. I only added require_once('includes/menu.inc');

Thanks :)