According to the API drupal_get_filename() looks in "modules/foo/foo.module sites/all/modules/foo/foo.module sites/example.com/modules/foo/foo.module" but in reality due to the implementation it never looks in "sites/all".

How to reproduce:

  • use drupal_get_path() to try and find the path to a template engine in "/sites/all/themes/engines".

What was expected:

  • drupal_get_path() should find the engine.

What happened instead:

  • drupal_get_path() returns nothing because drupal_get_filename() doesn't look in the correct directory.

This happens because "conf_path()" returns the directory where the site config is.

 else {
    // Fallback to searching the filesystem if the database connection is
    // not established or the requested file is not found.
    $config = conf_path(); // this will never return "sites/all/"
    $dir = (($type == 'theme_engine') ? 'themes/engines' : "${type}s");
    $file = (($type == 'theme_engine') ? "$name.engine" : "$name.$type");

    foreach (array("$config/$dir/$file", "$config/$dir/$name/$file", "$dir/$file", "$dir/$name/$file") as $file) {
      if (file_exists($file)) {
        $files[$type][$name] = $file;
        break;
      }
    }
  }

this can be easily fixed by adding two more paths to the search array:

else {
    // Fallback to searching the filesystem if the database connection is
    // not established or the requested file is not found.
    $config = conf_path(); // this will never return "sites/all/"
    $dir = (($type == 'theme_engine') ? 'themes/engines' : "${type}s");
    $file = (($type == 'theme_engine') ? "$name.engine" : "$name.$type");

    foreach (array("$config/$dir/$file", "$config/$dir/$name/$file","$config/../all/$dir/$file", "$config/../all/$dir/$name/$file", "$dir/$file", "$dir/$name/$file") as $file) {
      if (file_exists($file)) {
        $files[$type][$name] = $file;
        break;
      }
    }
  }

Unless I've just been staring at this too long and overlooked something, either the docs are wrong or the function is wrong... but its an easy fix :)

Comments

XRaptor’s picture

Status: Active » Closed (duplicate)

** Duplicate of http://drupal.org/node/344505 **

Somehow I missed that bug report when I searched the first time, sorry.