You are here

public function ExtensionList::getPathname in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Extension/ExtensionList.php \Drupal\Core\Extension\ExtensionList::getPathname()
  2. 9 core/lib/Drupal/Core/Extension/ExtensionList.php \Drupal\Core\Extension\ExtensionList::getPathname()

Gets the info file path for an extension.

The info path, whether provided, cached, or retrieved from the database, is only returned if the file exists.

This function plays a key role in allowing Drupal's extensions (modules, themes, profiles, theme_engines, etc.) to be located in different places depending on a site's configuration. For example, a module 'foo' may legally be located in any of these four places:

  • core/modules/foo/foo.info.yml
  • modules/foo/foo.info.yml
  • sites/all/modules/foo/foo.info.yml
  • sites/example.com/modules/foo/foo.info.yml

while a theme 'bar' may be located in any of the following four places:

  • core/themes/bar/bar.info.yml
  • themes/bar/bar.info.yml
  • sites/all/themes/bar/bar.info.yml
  • sites/example.com/themes/bar/bar.info.yml

An installation profile maybe be located in any of the following places:

  • core/profiles/baz/baz.info.yml
  • profiles/baz/baz.info.yml

Calling ExtensionList::getPathname('foo') will give you one of the above, depending on where the extension is located and what type it is.

Parameters

string $extension_name: The machine name of the extension for which the pathname is requested.

Return value

string The drupal-root relative filename and path of the requested extension's .info.yml file.

Throws

\Drupal\Core\Extension\Exception\UnknownExtensionException If there is no extension with the supplied machine name.

File

core/lib/Drupal/Core/Extension/ExtensionList.php, line 512

Class

ExtensionList
Provides available extensions.

Namespace

Drupal\Core\Extension

Code

public function getPathname($extension_name) {
  if (isset($this->addedPathNames[$extension_name])) {
    return $this->addedPathNames[$extension_name];
  }
  elseif (isset($this->pathNames[$extension_name])) {
    return $this->pathNames[$extension_name];
  }
  elseif (($path_names = $this
    ->getPathnames()) && isset($path_names[$extension_name])) {
    return $path_names[$extension_name];
  }
  throw new UnknownExtensionException("The {$this->type} {$extension_name} does not exist.");
}