diff --git a/core/lib/Drupal/Core/Extension/ExtensionList.php b/core/lib/Drupal/Core/Extension/ExtensionList.php index a7cc21d..e50cda5 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ExtensionList.php @@ -377,11 +377,9 @@ public function getAllInstalledInfo() { * An array of arrays of .info.yml entries keyed by the extension name. */ protected function recalculateInfo() { - $info = []; - foreach ($this->listExtensions() as $extension_name => $extension) { - $info[$extension_name] = $extension->info; - } - return $info; + return array_map(function (Extension $extension) { + return $extension->info; + }, $this->listExtensions()); } /** @@ -420,13 +418,12 @@ public function getFilenames() { * An array of .info.yml file locations keyed by the extension name. */ protected function recalculateFilenames() { - $file_names = []; $extensions = $this->listExtensions(); ksort($extensions); - foreach ($extensions as $name => $extension) { - $file_names[$name] = $extension->getPathname(); - } - return $file_names; + + return array_map(function (Extension $extension) { + return $extension->getPathname(); + }, $extensions); } /** @@ -443,6 +440,8 @@ protected function recalculateFilenames() { * @param string $filename * The filename of the extension which is to be set explicitly rather * than by consulting the dynamic extension listing. + * + * @internal */ public function setFilename($extension_name, $filename) { $this->addedFileNames[$extension_name] = $filename; @@ -457,14 +456,14 @@ public function setFilename($extension_name, $filename) { * 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 three places: + * 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 similar places: + * 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 @@ -513,4 +512,14 @@ public function getPath($extension_name) { return dirname($this->getFilename($extension_name)); } + /** + * Wraps drupal_get_profile(). + * + * @todo Replace drupal_get_profile() once + * https://www.drupal.org/node/2156401 is in. + */ + protected function getProfile() { + return drupal_get_profile(); + } + } diff --git a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php index b09a67b..e154c8b 100644 --- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php @@ -87,10 +87,11 @@ protected function getExtensionDiscovery() { * Gets the processed active profile object, or null. * * @return \Drupal\Core\Extension\Extension|null + * The active profile, if there is one. */ protected function getActiveProfile() { $profiles = $this->profileList->listExtensions(); - $active_profile_name = drupal_get_profile(); + $active_profile_name = $this->getProfile(); if ($active_profile_name && isset($profiles[$active_profile_name])) { return $profiles[$active_profile_name]; } @@ -108,9 +109,7 @@ protected function doScanExtensions() { $profiles = $profile_extension_discovery->scan('profile'); // Modify the active profile object that was previously added to the module // list. - // @todo Replace drupal_get_profile() once - // https://www.drupal.org/node/2156401 is in. - $active_profile_name = drupal_get_profile(); + $active_profile_name = $this->getProfile(); if ($active_profile_name && isset($profiles[$active_profile_name])) { $extensions[$active_profile_name] = $active_profile = $profiles[$active_profile_name]; $active_profile = $extensions[$active_profile_name]; diff --git a/core/lib/Drupal/Core/Extension/ProfileExtensionList.php b/core/lib/Drupal/Core/Extension/ProfileExtensionList.php index 7c3ecb3..a6bf443 100644 --- a/core/lib/Drupal/Core/Extension/ProfileExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ProfileExtensionList.php @@ -22,7 +22,7 @@ class ProfileExtensionList extends ExtensionList { * {@inheritdoc} */ protected function getInstalledExtensionsNames() { - return [drupal_get_profile()]; + return [$this->getProfile()]; } }