diff --git a/core/lib/Drupal/Core/Extension/ExtensionList.php b/core/lib/Drupal/Core/Extension/ExtensionList.php index ba7aaeb..d4a58c9 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ExtensionList.php @@ -285,7 +285,7 @@ protected function doListExtensions() { * * @param string $name * The name of an extension whose information shall be returned. If $name - * does not exist exception is thrown. + * does not exist or is not installed an exception is thrown. * * @return mixed[] * An associative array of extension information. @@ -295,24 +295,26 @@ protected function doListExtensions() { */ public function getInfo($name) { // Ensure that $this->extensionInfo is primed. - $this->getAllInfo(); - if (isset($this->extensionInfo[$name])) { - return $this->extensionInfo[$name]; + $all_info = $this->getAllInfo(TRUE); + if (isset($all_info[$name])) { + return $all_info[$name]; } - throw new \InvalidArgumentException("The {$this->type} $name does not exist."); + throw new \InvalidArgumentException("The {$this->type} $name does not exist or is not installed"); } /** * Returns an array of information about enabled modules or themes. * - * This function returns the contents of the .info.yml file for each installed - * extension. + * This function returns the contents of the .info.yml file. * - * @return array[] + * @param bool $installed + * If TRUE, just installed info will be returned. + * + * @return \array[] * An associative array of extension information keyed by name. If no * records are available, an empty array is returned. */ - public function getAllInfo() { + public function getAllInfo($installed = TRUE) { if (!isset($this->extensionInfo)) { $cache_key = "system.{$this->type}.info"; if ($cache = $this->cache->get($cache_key)) { @@ -324,6 +326,7 @@ public function getAllInfo() { } $this->extensionInfo = $info; } + return $this->extensionInfo; } diff --git a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php index 996f2ca..260df7b 100644 --- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php @@ -69,7 +69,7 @@ public function __construct($root, $type, CacheBackendInterface $cache, InfoPars protected function getExtensionDiscovery() { $discovery = parent::getExtensionDiscovery(); - if (NULL !== $active_profile = $this->getActiveProfile()) { + if ($active_profile = $this->getActiveProfile()) { // Set the profile in the ExtensionDiscovery so we can scan from the right // profile directory. $discovery->setProfileDirectories([ @@ -86,7 +86,7 @@ protected function getExtensionDiscovery() { protected function doScanExtensions() { $extensions = parent::doScanExtensions(); - if (NULL !== $active_profile = $this->getActiveProfile()) { + if ($active_profile = $this->getActiveProfile()) { // Include the installation profile in modules that are loaded. $extensions[$active_profile->getName()] = $active_profile; // Installation profile hooks are always executed last. @@ -157,6 +157,17 @@ protected function doListExtensions() { } /** + * {@inheritdoc} + */ + public function getAllInfo($installed = TRUE) { + $info = parent::getAllInfo($installed); + if ($installed) { + $info = array_intersect_key($info, $this->moduleHandler->getModuleList()); + } + return $info; + } + + /** * Marks dependencies of required modules as 'required', recursively. * * @param \Drupal\Core\Extension\Extension $module