diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 5d442ac..4800900 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -701,14 +701,13 @@ function drupal_get_filename($type, $name, $filename = NULL) { $files[$type][$name] = $filename; } elseif (!isset($files[$type][$name])) { - $container = \Drupal::getContainer(); - // For modules, first consult ModuleHandler for the current module list. - if ($type == 'module' && !isset($files[$type]) && $container->has('module_handler')) { + // For modules, consult ModuleHandler for the current module list. + if ($type == 'module' && !isset($files[$type]) && \Drupal::hasService('module_handler')) { $files[$type] = \Drupal::moduleHandler()->getModuleList(); } - // Consult the extension lists prepared by system_rebuild_module_data() and + // Consult the extension list prepared by system_rebuild_module_data() and // system_rebuild_theme_data() in State. - if (!isset($files[$type][$name]) && $container->has('state')) { + if (!isset($files[$type][$name]) && \Drupal::hasService('state')) { $file_list = \Drupal::state()->get('system.' . $type . '.files'); if ($file_list && isset($file_list[$name]) && file_exists(DRUPAL_ROOT . '/' . $file_list[$name])) { $files[$type][$name] = $file_list[$name]; @@ -716,13 +715,12 @@ function drupal_get_filename($type, $name, $filename = NULL) { } // Fallback to ExtensionDiscovery. if (!isset($files[$type][$name])) { - $dir = ($type == 'theme_engine' ? 'themes/engines' : $original_type . 's'); $listing = new ExtensionDiscovery(); // Prevent an infinite recursion by this legacy function. if ($original_type == 'profile') { $listing->setProfileDirectories(array()); } - foreach ($listing->scan($dir) as $extension_name => $file) { + foreach ($listing->scan($original_type) as $extension_name => $file) { $files[$type][$extension_name] = $file->uri; } } diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index fd1bc6f..7b06081 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -503,7 +503,7 @@ function install_begin_request(&$install_state) { // Add list of all available profiles to the installation state. $listing = new ExtensionDiscovery(); $listing->setProfileDirectories(array()); - $install_state['profiles'] += $listing->scan('profiles'); + $install_state['profiles'] += $listing->scan('profile'); // Prime drupal_get_filename()'s static cache. foreach ($install_state['profiles'] as $name => $profile) { diff --git a/core/includes/install.inc b/core/includes/install.inc index af5f773..c268eb7 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -568,7 +568,7 @@ function drupal_verify_profile($install_state) { // Get the list of available modules for the selected installation profile. $listing = new ExtensionDiscovery(); $present_modules = array(); - foreach ($listing->scan('modules') as $present_module) { + foreach ($listing->scan('module') as $present_module) { $present_modules[] = $present_module->name; } diff --git a/core/includes/module.inc b/core/includes/module.inc index 66fa1be..453de05 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -287,7 +287,7 @@ function module_uninstall($module_list = array(), $uninstall_dependents = TRUE) */ function drupal_required_modules() { $listing = new ExtensionDiscovery(); - $files = $listing->scan('modules'); + $files = $listing->scan('module'); $required = array(); // Unless called by the installer, an installation profile is required and diff --git a/core/lib/Drupal/Core/Config/InstallStorage.php b/core/lib/Drupal/Core/Config/InstallStorage.php index 5d05790..f86ec10 100644 --- a/core/lib/Drupal/Core/Config/InstallStorage.php +++ b/core/lib/Drupal/Core/Config/InstallStorage.php @@ -117,8 +117,8 @@ protected function getAllFolders() { $this->folders += $this->getComponentNames('profile', array($profile)); } $listing = new ExtensionDiscovery(); - $this->folders += $this->getComponentNames('module', array_keys($listing->scan('modules'))); - $this->folders += $this->getComponentNames('theme', array_keys($listing->scan('themes'))); + $this->folders += $this->getComponentNames('module', array_keys($listing->scan('module'))); + $this->folders += $this->getComponentNames('theme', array_keys($listing->scan('theme'))); } return $this->folders; } diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 73c4276..2183096 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -300,7 +300,7 @@ protected function moduleData($module) { // First, find profiles. $listing = new ExtensionDiscovery(); $listing->setProfileDirectories(array()); - $all_profiles = $listing->scan('profiles'); + $all_profiles = $listing->scan('profile'); $profiles = array_intersect_key($all_profiles, $this->moduleList); // If a module is within a profile directory but specifies another @@ -319,7 +319,7 @@ protected function moduleData($module) { $listing->setProfileDirectories($profile_directories); // Now find modules. - $this->moduleData = $profiles + $listing->scan('modules'); + $this->moduleData = $profiles + $listing->scan('module'); } return isset($this->moduleData[$module]) ? $this->moduleData[$module] : FALSE; } diff --git a/core/lib/Drupal/Core/Extension/Extension.php b/core/lib/Drupal/Core/Extension/Extension.php index c810121..173b779 100644 --- a/core/lib/Drupal/Core/Extension/Extension.php +++ b/core/lib/Drupal/Core/Extension/Extension.php @@ -61,7 +61,7 @@ class Extension implements \Serializable { protected $splFileInfo; /* - // @see __get() + // @todo See __get() below. protected $infoParser; protected $info; */ @@ -188,7 +188,9 @@ public function unserialize($data) { $this->$property = $value; } /* - // @see serialize() + // @todo Not possible as long as ThemeHandler::listInfo(), + // ThemeHandler::rebuildThemeData(), and system_list() are adding + // arbitrary custom properties to the Extension object. $this->type = $data['type']; $this->infoPathname = $data['pathname']; $this->name = basename($data['pathname'], '.info.yml'); diff --git a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php index ffb2745..c0ac5e9 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php +++ b/core/lib/Drupal/Core/Extension/ExtensionDiscovery.php @@ -77,7 +77,7 @@ class ExtensionDiscovery { * modules: * @code * $listing = new ExtensionDiscovery(); - * $modules = $listing->scan('modules'); + * $modules = $listing->scan('module'); * @endcode * * The following directories will be searched (in the order stated): @@ -92,10 +92,9 @@ class ExtensionDiscovery { * will take precedence over extensions found earlier - unless they are not * compatible with the current version of Drupal core. * - * @param string $directory - * The subdirectory name in which to search for extensions. For example, - * 'modules' will recursively search all 'modules' directories for - * extensions of type 'module'. + * @param string $type + * The extension type to search for. One of 'profile', 'module', 'theme', or + * 'theme_engine'. * @param bool $include_tests * (optional) Whether to include test extensions. Defaults to FALSE when not * in a test environment; i.e., all 'tests' directories are excluded in the @@ -104,16 +103,7 @@ class ExtensionDiscovery { * @return \Drupal\Core\Extension\Extension[] * An associative array of Extension objects, keyed by extension name. */ - public function scan($directory, $include_tests = NULL) { - // @todo Fix callers to pass $type. - // @see drupal_get_filename() - if ($directory == 'themes/engines') { - $type = 'theme_engine'; - } - else { - $type = substr($directory, 0, -1); - } - + public function scan($type, $include_tests = NULL) { // Determine the installation profile directories to scan for extensions, // unless explicit profile directories have been set. if (!isset($this->profileDirectories)) { diff --git a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php index 024eeb6..3012627 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php @@ -71,7 +71,8 @@ public function setModuleList(array $module_list = array()); * * @param array $modules * An array of module objects keyed by module name. Each object contains - * information discovered during a Drupal\Core\Extension\ExtensionDiscovery scan. + * information discovered during a Drupal\Core\Extension\ExtensionDiscovery + * scan. * * @return * The same array with the new keys for each module: diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index 696f432..d7eef35 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -243,8 +243,8 @@ public function reset() { */ public function rebuildThemeData() { $listing = $this->getExtensionDiscovery(); - $themes = $listing->scan('themes'); - $engines = $listing->scan('themes/engines'); + $themes = $listing->scan('theme'); + $engines = $listing->scan('theme_engine'); // Set defaults for theme info. $defaults = array( diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/TestInstallStorage.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/TestInstallStorage.php index 4782304..bae2dd0 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/TestInstallStorage.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/TestInstallStorage.php @@ -24,9 +24,9 @@ class TestInstallStorage extends InstallStorage { protected function getAllFolders() { if (!isset($this->folders)) { $listing = new ExtensionDiscovery(); - $this->folders = $this->getComponentNames('profile', array_keys($listing->scan('profiles'))); - $this->folders += $this->getComponentNames('module', array_keys($listing->scan('modules'))); - $this->folders += $this->getComponentNames('theme', array_keys($listing->scan('themes'))); + $this->folders = $this->getComponentNames('profile', array_keys($listing->scan('profile'))); + $this->folders += $this->getComponentNames('module', array_keys($listing->scan('module'))); + $this->folders += $this->getComponentNames('theme', array_keys($listing->scan('theme'))); } return $this->folders; } diff --git a/core/modules/config/tests/config_test/lib/Drupal/config_test/TestSchemaStorage.php b/core/modules/config/tests/config_test/lib/Drupal/config_test/TestSchemaStorage.php index bf5a6fc..aae81c3 100644 --- a/core/modules/config/tests/config_test/lib/Drupal/config_test/TestSchemaStorage.php +++ b/core/modules/config/tests/config_test/lib/Drupal/config_test/TestSchemaStorage.php @@ -32,9 +32,9 @@ protected function getAllFolders() { if (!isset($this->folders)) { $listing = new ExtensionDiscovery(); $this->folders = $this->getBaseDataTypeSchema(); - $this->folders += $this->getComponentNames('profile', array_keys($listing->scan('profiles'))); - $this->folders += $this->getComponentNames('module', array_keys($listing->scan('modules'))); - $this->folders += $this->getComponentNames('theme', array_keys($listing->scan('themes'))); + $this->folders += $this->getComponentNames('profile', array_keys($listing->scan('profile'))); + $this->folders += $this->getComponentNames('module', array_keys($listing->scan('module'))); + $this->folders += $this->getComponentNames('theme', array_keys($listing->scan('theme'))); } return $this->folders; } diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 58289e7..12e9814 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -462,7 +462,7 @@ function simpletest_test_get_all($module = NULL) { else { // Select all PSR-0 classes in the Tests namespace of all modules. $listing = new ExtensionDiscovery(); - $all_data = $listing->scan('modules', TRUE); + $all_data = $listing->scan('module', TRUE); // If module is set then we keep only that one module. if (isset($module)) { $all_data = array( @@ -470,8 +470,8 @@ function simpletest_test_get_all($module = NULL) { ); } else { - $all_data += $listing->scan('profiles', TRUE); - $all_data += $listing->scan('themes', TRUE); + $all_data += $listing->scan('profile', TRUE); + $all_data += $listing->scan('theme', TRUE); } $classes = array(); foreach ($all_data as $name => $data) { @@ -551,12 +551,11 @@ function simpletest_test_get_all($module = NULL) { function simpletest_classloader_register() { // Use the same cache prefix as simpletest_test_get_all(). $cid = "simpletest::all"; - // @see drupal_get_filename() $types = array( - 'theme_engine' => 'themes/engines', - 'module' => 'modules', - 'theme' => 'themes', - 'profile' => 'profiles', + 'theme_engine', + 'module', + 'theme', + 'profile', ); if ($cache = cache()->get($cid)) { @@ -565,8 +564,8 @@ function simpletest_classloader_register() { else { $listing = new ExtensionDiscovery(); $extensions = array(); - foreach ($types as $type => $dir) { - foreach ($listing->scan($dir, TRUE) as $name => $file) { + foreach ($types as $type) { + foreach ($listing->scan($type, TRUE) as $name => $file) { $extensions[$type][$name] = $file->uri; } } @@ -574,7 +573,7 @@ function simpletest_classloader_register() { } $classloader = drupal_classloader(); - foreach ($types as $type => $info) { + foreach ($types as $type) { foreach ($extensions[$type] as $name => $uri) { drupal_classloader_register($name, dirname($uri)); $classloader->add('Drupal\\' . $name . '\\Tests', DRUPAL_ROOT . '/' . dirname($uri) . '/tests'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/SystemListingTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/SystemListingTest.php index 742d8da..d37fd4b 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/SystemListingTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/SystemListingTest.php @@ -58,7 +58,7 @@ function testDirectoryPrecedence() { // expected. $listing = new ExtensionDiscovery(); $listing->setProfileDirectories(array('core/profiles/testing')); - $files = $listing->scan('modules'); + $files = $listing->scan('module'); foreach ($expected_directories as $module => $directories) { $expected_directory = array_shift($directories); $expected_uri = "$expected_directory/$module/$module.module"; diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php index ea93407..dda6fb0 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/EntityFilteringThemeTest.php @@ -84,7 +84,7 @@ function setUp() { // Enable all available non-testing themes. $listing = new ExtensionDiscovery(); - $this->themes = $listing->scan('themes', FALSE); + $this->themes = $listing->scan('theme', FALSE); theme_enable(array_keys($this->themes)); // Create a test user. diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 1d36e5e..ab22256 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -2562,10 +2562,10 @@ function system_get_info($type, $name = NULL) { function _system_rebuild_module_data() { $listing = new ExtensionDiscovery(); // Find modules - $modules = $listing->scan('modules'); + $modules = $listing->scan('module'); // Find installation profiles. - $profiles = $listing->scan('profiles'); + $profiles = $listing->scan('profile'); // Include the installation profile in modules that are loaded. if ($profile = drupal_get_profile()) {