diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 01b1393bba..135942637c 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -432,8 +432,8 @@ function install_begin_request($class_loader, &$install_state) { } // Before having installed the system module and being able to do a module - // rebuild, prime the drupal_get_filename() static cache with the module's - // exact location. + // rebuild, prime the drupal_get_filename() static cache with the system + // module's location. // @todo Remove as part of https://www.drupal.org/node/2186491 drupal_get_filename('module', 'system', 'core/modules/system/system.info.yml'); @@ -1063,7 +1063,7 @@ function install_base_system(&$install_state) { file_ensure_htaccess(); // Prime the drupal_get_filename() static cache with the user module's - // exact location. + // location. // @todo Remove as part of https://www.drupal.org/node/2186491 drupal_get_filename('module', 'user', 'core/modules/user/user.info.yml'); diff --git a/core/lib/Drupal/Core/Extension/ExtensionList.php b/core/lib/Drupal/Core/Extension/ExtensionList.php index 1c46cec8bd..5e3bc921eb 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ExtensionList.php @@ -87,6 +87,8 @@ * over the discovered extension folders. * * @var string[] + * + * @internal */ protected $addedFileNames = []; @@ -94,6 +96,8 @@ * Static version of the added file names during the installer. * * @var string + * + * @internal */ protected static $staticAddedFileNames; @@ -159,15 +163,15 @@ public function reset() { $this->fileNames = NULL; try { - $this->state->delete($this->getFilenameCacheId()); + $this->state->delete($this->getFilenamesCacheId()); } catch (\Exception $e) { // Ignore exceptions caused by a non existing {key_value} table in the // early installer. } - $this->cache->delete($this->getFilenameCacheId()); - // We explicitly don't reset the addedFileNames as its sort of a static + $this->cache->delete($this->getFilenamesCacheId()); + // We explicitly don't reset the addedFileNames as it is sort of a static // cache. // @todo In the long run it would be great to add the reset, but the early // installer fails due to that. @@ -200,7 +204,7 @@ protected function getInfoCacheId() { * @return string * The filename cache ID. */ - protected function getFilenameCacheId() { + protected function getFilenamesCacheId() { return "system.{$this->type}.files"; } @@ -208,10 +212,11 @@ protected function getFilenameCacheId() { * Determines if an extension exists in the filesystem. * * @param string $extension_name - * The machine name of the extension. + * The extension machine name of the extension. * * @return bool - * TRUE if the extension exists (whether installed or not) and FALSE if not. + * TRUE if the extension exists (regardless installed or not) and FALSE if + * not. */ public function extensionExists($extension_name) { $extensions = $this->listExtensions(); @@ -222,13 +227,13 @@ public function extensionExists($extension_name) { * Returns the human-readable name of the extension. * * @param string $extension_name - * The extension name. + * The extension machine name. * * @return string * The human-readable name of the extension. * * @throws \InvalidArgumentException - * If there is no extension with the supplied machine name. + * If there is no extension with the supplied extension human name. */ public function getName($extension_name) { return $this->getExtension($extension_name)->info['name']; @@ -238,10 +243,10 @@ public function getName($extension_name) { * Returns a single extension. * * @param string $extension_name - * The extension name. + * The extension machine name. * * @return \Drupal\Core\Extension\Extension - * Processed extension object for the given machine name. + * Processed extension object for the given extension machine name. * * @throws \InvalidArgumentException * If there is no extension with the supplied name. @@ -259,7 +264,7 @@ public function getExtension($extension_name) { * Returns all available extensions. * * @return \Drupal\Core\Extension\Extension[] - * Processed extension objects, keyed by machine name. + * Processed extension objects, keyed by extension machine name. */ public function listExtensions() { if ($this->extensions !== NULL) { @@ -282,17 +287,17 @@ public function listExtensions() { * extensions to this raw listing. * * @return \Drupal\Core\Extension\Extension[] - * Unprocessed extension objects, keyed by machine name. + * Unprocessed extension objects, keyed by extension machine name. */ protected function doScanExtensions() { return $this->getExtensionDiscovery()->scan($this->type); } /** - * Build the actual list of extensions before caching it. + * Builds the list of extensions. * * @return \Drupal\Core\Extension\Extension[] - * Processed extension objects, keyed by machine name. + * Processed extension objects, keyed by extension machine name. * * @throws \Drupal\Core\Extension\InfoParserException * If one of the .info.yml files is incomplete, or causes a parsing error. @@ -310,7 +315,7 @@ protected function doListExtensions() { // contributed extensions to use for ordering extension lists. $extension->info['mtime'] = $extension->getMTime(); - // Merge in defaults and save. + // Merge extension type-specific defaults. $extension->info += $this->defaults; // Invoke hook_system_info_alter() to give installed modules a chance to @@ -356,13 +361,13 @@ public function getExtensionInfo($extension_name) { */ public function getAllAvailableInfo() { if ($this->extensionInfo === NULL) { - $cache_key = "system.{$this->type}.info"; - if ($cache = $this->cache->get($cache_key)) { + $cache_id = $this->getInfoCacheId(); + if ($cache = $this->cache->get($cache_id)) { $info = $cache->data; } else { $info = $this->recalculateInfo(); - $this->cache->set($cache_key, $info); + $this->cache->set($cache_id, $info); } $this->extensionInfo = $info; } @@ -371,10 +376,10 @@ public function getAllAvailableInfo() { } /** - * Returns installed extension names. + * Returns installed extension machine names. * * @return string[] - * The machine names of all installed extensions of this type. + * The extension machine names of all installed extensions of this type. */ abstract protected function getInstalledExtensionsNames(); @@ -395,11 +400,8 @@ public function getAllInstalledInfo() { /** * Generates the information from .info.yml files for extensions of this type. * - * The information is placed in cache with the "system.{extension_type}.info" - * key. - * * @return array[] - * An array of arrays of .info.yml entries keyed by the extension name. + * An array of arrays of .info.yml entries keyed by the extension machine name. */ protected function recalculateInfo() { return array_map(function (Extension $extension) { @@ -408,20 +410,18 @@ protected function recalculateInfo() { } /** - * Returns a list of extension file name keyed by extension name. + * Returns a list of extension file name keyed by extension machine name. * * @return string[] */ public function getFilenames() { if ($this->fileNames === NULL) { - $cache_id = $this->getFilenameCacheId(); + $cache_id = $this->getFilenamesCacheId(); if ($cache = $this->cache->get($cache_id)) { $file_names = $cache->data; } // We use $file_names below. - elseif ($file_names = $this->state->get($cache_id)) { - } - else { + elseif (!$file_names = $this->state->get($cache_id)) { $file_names = $this->recalculateFilenames(); // Store filenames to allow static::getFilename() to retrieve them // without having to rebuild or scan the filesystem. @@ -436,11 +436,8 @@ public function getFilenames() { /** * Generates a sorted list of .info.yml file locations for all extensions. * - * The information is placed in cache with the "system.{extension_type}.files" - * key. - * * @return string[] - * An array of .info.yml file locations keyed by the extension name. + * An array of .info.yml file locations keyed by the extension machine name. */ protected function recalculateFilenames() { $extensions = $this->listExtensions(); @@ -483,7 +480,7 @@ public function setFilename($extension_name, $filename) { } /** - * Gets the filename for a system resource. + * Gets the filename for an extension. * * The filename, whether provided, cached, or retrieved from the database, is * only returned if the file exists. @@ -493,17 +490,22 @@ public function setFilename($extension_name, $filename) { * 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 + * - 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 + * - 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::getFilename('foo') will give you one of the above, * depending on where the extension is located and what type it is. @@ -541,7 +543,7 @@ public function getFilename($extension_name) { * The name of the extension for which the path is requested. * * @return string - * The drupal-root-relative path to the specified extension. + * The Drupal-root-relative path to the specified extension. * * @throws \InvalidArgumentException * If there is no extension with the supplied name. diff --git a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php index 5e8be979da..3bcac67105 100644 --- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php @@ -40,10 +40,6 @@ class ModuleExtensionList extends ExtensionList { protected $profileList; /** - */ - protected $moduleLocations; - - /** * Constructs a new ModuleExtensionList instance. * * @param string $root @@ -73,7 +69,7 @@ public function __construct($root, $type, CacheBackendInterface $cache, InfoPars $this->configFactory = $config_factory; $this->profileList = $profile_list; - // Use the information from the container. + // Use the information from the container. This is an optimization. foreach ($container_modules_info as $module_name => $info) { $this->setFilename($module_name, $info['pathname']); } @@ -98,7 +94,7 @@ protected function getExtensionDiscovery() { * @param \Drupal\Core\Extension\ExtensionDiscovery $discovery * The extension discovery. * - * @return array + * @return string[] * Paths to all installation profiles. */ protected function getProfileDirectories(ExtensionDiscovery $discovery) { @@ -160,7 +156,6 @@ protected function doScanExtensions() { * {@inheritdoc} */ protected function doListExtensions() { - // Find modules. $extensions = parent::doListExtensions(); // It is possible that a module was marked as required by @@ -190,7 +185,7 @@ protected function doListExtensions() { $active_profile->info['hidden'] = TRUE; } - // The installation profile is required, if it's a valid module. + // The installation profile is required. $active_profile->info['required'] = TRUE; // Add a default distribution name if the profile did not provide one. // @see install_profile_info() @@ -224,7 +219,7 @@ protected function ensureRequiredDependencies(Extension $module, array $modules $dependency_name = ModuleHandler::parseDependency($dependency)['name']; if (!isset($modules[$dependency_name]->info['required'])) { $modules[$dependency_name]->info['required'] = TRUE; - $modules[$dependency_name]->info['explanation'] = $this->t('Dependency of required module @module', array('@module' => $module->info['name'])); + $modules[$dependency_name]->info['explanation'] = $this->t('Dependency of required module @module', ['@module' => $module->info['name']]); // Ensure any dependencies it has are required. $this->ensureRequiredDependencies($modules[$dependency_name], $modules); }