function drupal_parse_info_file

Parses Drupal module and theme .info.yml files.

Info files are NOT for placing arbitrary theme and module-specific settings. Use Config::get() and Config::set()->save() for that. Info files are formatted as YAML. If the 'version' key is set to 'VERSION' in any info file, then the value will be substituted with the current version of Drupal core.

Information stored in a module .info.yml file:

  • name: The real name of the module for display purposes.
  • description: A brief description of the module.
  • dependencies: An array of shortnames of other modules this module requires.
  • package: The name of the package of modules this module belongs to.

See forum.info.yml for an example of a module .info.yml file.

Information stored in a theme .info.yml file:

  • name: The real name of the theme for display purposes.
  • description: Brief description.
  • screenshot: Path to screenshot relative to the theme's .info.yml file.
  • engine: Theme engine; typically twig.
  • base theme: Name of a base theme, if applicable.
  • regions: Listed regions.
  • features: Features available.
  • stylesheets: Theme stylesheets.
  • scripts: Theme scripts.

See bartik.info.yml for an example of a theme .info.yml file.

Parameters

string $filename: The file we are parsing. Accepts file with relative or absolute path.

Return value

array The info array.

9 calls to drupal_parse_info_file()

File

drupal/core/includes/common.inc, line 5469
Common functions that many Drupal modules will need to reference.

Code

function drupal_parse_info_file($filename) {
  $info =& drupal_static(__FUNCTION__, array());
  if (!isset($info[$filename])) {
    if (!file_exists($filename)) {
      $info[$filename] = array();
    }
    else {
      $parser = new Parser();
      $info[$filename] = $parser
        ->parse(file_get_contents($filename));
      if (isset($info[$filename]['version']) && $info[$filename]['version'] === 'VERSION') {
        $info[$filename]['version'] = VERSION;
      }
    }
  }
  return $info[$filename];
}