Same name and namespace in other branches
  1. 4.6.x includes/bootstrap.inc \drupal_get_filename()
  2. 5.x includes/bootstrap.inc \drupal_get_filename()
  3. 6.x includes/bootstrap.inc \drupal_get_filename()
  4. 7.x includes/bootstrap.inc \drupal_get_filename()
  5. 8.9.x core/includes/bootstrap.inc \drupal_get_filename()
  6. 9 core/includes/bootstrap.inc \drupal_get_filename()

Returns and optionally sets the filename for a system item (module, theme, etc.). The filename, whether provided, cached, or retrieved from the database, is only returned if the file exists.

Parameters

$type: The type of the item (i.e. theme, theme_engine, module).

$name: The name of the item for which the filename is requested.

$filename: The filename of the item if it is to be set explicitly rather than by consulting the database.

Return value

The filename of the requested item.

5 calls to drupal_get_filename()
drupal_get_path in includes/common.inc
Returns the path to a system item (module, theme, etc.).
drupal_load in includes/bootstrap.inc
Includes a file with the provided type and name. This prevents including a theme, engine, module, etc., more than once.
module_list in includes/module.inc
Collect a list of all loaded modules. During the bootstrap, return only vital modules. See bootstrap.inc
system_modules in modules/system.module
Menu callback; displays a listing of all modules.
system_theme_data in modules/system.module
Collect data about all currently available themes

File

includes/bootstrap.inc, line 202
Functions that need to be loaded on every Drupal request.

Code

function drupal_get_filename($type, $name, $filename = NULL) {
  static $files = array();
  if (!isset($files[$type])) {
    $files[$type] = array();
  }
  if (!empty($filename) && file_exists($filename)) {
    $files[$type][$name] = $filename;
  }
  elseif (isset($files[$type][$name])) {

    // nothing
  }
  elseif (($file = db_result(db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))) && file_exists($file)) {
    $files[$type][$name] = $file;
  }
  else {
    $config = conf_path();
    $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;
      }
    }
  }
  return $files[$type][$name];
}