diff --git a/core/includes/install.core.inc b/core/includes/install.core.inc index 41cc436..ff47be3 100644 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -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 - // location. + // exact 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/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 44e653f..3f53d04 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -840,10 +840,7 @@ protected function initializeContainer() { if (isset($this->container)) { // Save the id of the currently logged in user. if ($this->container->initialized('current_user')) { - /** @var \Drupal\Core\Session\AccountProxyInterface $current_user */ - $current_user = $this->container->get('current_user'); - // Ensure to not accidentally initialize the user. - $current_user_id = $current_user->hasAccount() ? $current_user->id() : 0; + $current_user_id = $this->container->get('current_user')->id(); } // If there is a session, close and save it. diff --git a/core/lib/Drupal/Core/Extension/ExtensionList.php b/core/lib/Drupal/Core/Extension/ExtensionList.php index 7a54d3c..bb48eca 100644 --- a/core/lib/Drupal/Core/Extension/ExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ExtensionList.php @@ -8,7 +8,7 @@ /** * Provides available extensions. * - * The extension list is per extension type, like module theme and profile. + * The extension list is per extension type (i.e. module, theme, or profile). */ abstract class ExtensionList { @@ -333,7 +333,7 @@ protected function doListExtensions() { * extension. * * @param string $extension_name - * The name of an extension whose information shall be returned. + * The machine name of an extension whose information shall be returned. * * @return mixed[] * An associative array of extension information. @@ -458,7 +458,7 @@ protected function recalculatePathnames() { * It is not recommended to call this method except in those rare cases. * * @param string $extension_name - * The name of the extension for which the filename is requested. + * The machine name of the extension for which the filename is requested. * @param string $pathname * The pathname of the extension which is to be set explicitly rather * than by consulting the dynamic extension listing. @@ -472,8 +472,8 @@ public function setPathname($extension_name, $pathname) { // In the early installer the container is rebuilt multiple times. Therefore // we have to keep the added filenames across those rebuilds. This is not a - // final design, but rather just a workaround resolved at some point, - // hopefully. + // final design, but rather just a workaround that should be resolved at + // some point. if (!empty($GLOBALS['install_state'])) { static::$staticAddedPathNames[$extension_name] = $pathname; } @@ -511,7 +511,7 @@ public function setPathname($extension_name, $pathname) { * depending on where the extension is located and what type it is. * * @param string $extension_name - * The name of the extension for which the pathname is requested. + * The machine name of the extension for which the pathname is requested. * * @return string * The filename of the requested extension's .info.yml file. @@ -540,7 +540,7 @@ public function getPathname($extension_name) { * Gets the path to an extension of a specific type (module, theme, etc.). * * @param string $extension_name - * The name of the extension for which the path is requested. + * The machine name of the extension for which the path is requested. * * @return string * The Drupal-root-relative path to the specified extension. diff --git a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php index 00f154b..cd535a0 100644 --- a/core/lib/Drupal/Core/Extension/ModuleExtensionList.php +++ b/core/lib/Drupal/Core/Extension/ModuleExtensionList.php @@ -5,15 +5,13 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\State\StateInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Provides a list of available modules. */ class ModuleExtensionList extends ExtensionList { - use StringTranslationTrait; - /** * {@inheritdoc} */ @@ -219,7 +217,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', ['@module' => $module->info['name']]); + $modules[$dependency_name]->info['explanation'] = new TranslatableMarkup('Dependency of required module @module', ['@module' => $module->info['name']]); // Ensure any dependencies it has are required. $this->ensureRequiredDependencies($modules[$dependency_name], $modules); } diff --git a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php index 0253358..6b2738c 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandlerInterface.php @@ -306,9 +306,6 @@ public function getModuleDirectories(); * @return string * Returns the human readable name of the module or the machine name passed * in if no matching module is found. - * - * @deprecated in Drupal 8.4.0, will be removed before Drupal 9.0.0. - * Use \Drupal::service('extension.list.module')->getName() instead. */ public function getName($module); diff --git a/core/lib/Drupal/Core/Extension/module.api.php b/core/lib/Drupal/Core/Extension/module.api.php index 944d354..fde4e78 100644 --- a/core/lib/Drupal/Core/Extension/module.api.php +++ b/core/lib/Drupal/Core/Extension/module.api.php @@ -132,10 +132,10 @@ function hook_module_implements_alter(&$implementations, $hook) { /** * Alter the information parsed from module and theme .info.yml files. * - * This hook is invoked in _system_rebuild_module_data() and in - * \Drupal\Core\Extension\ThemeHandlerInterface::rebuildThemeData(). A module - * may implement this hook in order to add to or alter the data generated by - * reading the .info.yml file with \Drupal\Core\Extension\InfoParser. + * This hook is invoked in ExtensionList::doListExtensions() and in + * ThemeHandlerInterface::rebuildThemeData(). A module may implement this hook + * in order to add to or alter the data generated by reading the .info.yml file + * with \Drupal\Core\Extension\InfoParser. * * Using implementations of this hook to make modules required by setting the * $info['required'] key is discouraged. Doing so will slow down the module @@ -150,7 +150,9 @@ function hook_module_implements_alter(&$implementations, $hook) { * Either 'module' or 'theme', depending on the type of .info.yml file that * was passed. * + * @see \Drupal\Core\Extension\ExtensionList::doListExtensions() * @see \Drupal\Core\Extension\ModuleUninstallValidatorInterface + * @see \Drupal\Core\Extension\ThemeHandlerInterface::rebuildThemeData() */ function hook_system_info_alter(array &$info, \Drupal\Core\Extension\Extension $file, $type) { // Only fill this in if the .info.yml file does not define a 'datestamp'. diff --git a/core/lib/Drupal/Core/Session/AccountProxy.php b/core/lib/Drupal/Core/Session/AccountProxy.php index 750cf0a..afe800b 100644 --- a/core/lib/Drupal/Core/Session/AccountProxy.php +++ b/core/lib/Drupal/Core/Session/AccountProxy.php @@ -55,13 +55,6 @@ public function setAccount(AccountInterface $account) { /** * {@inheritdoc} */ - public function hasAccount() { - return isset($this->account); - } - - /** - * {@inheritdoc} - */ public function getAccount() { if (!isset($this->account)) { if ($this->id) { diff --git a/core/lib/Drupal/Core/Session/AccountProxyInterface.php b/core/lib/Drupal/Core/Session/AccountProxyInterface.php index b7525aa..378b89d 100644 --- a/core/lib/Drupal/Core/Session/AccountProxyInterface.php +++ b/core/lib/Drupal/Core/Session/AccountProxyInterface.php @@ -6,7 +6,6 @@ * Defines an interface for a service which has the current account stored. * * @ingroup user_api - * @internal */ interface AccountProxyInterface extends AccountInterface { @@ -44,12 +43,4 @@ public function getAccount(); */ public function setInitialAccountId($account_id); - /** - * Checks whether an account is currently wrapped. - * - * @return bool - * TRUE, if an account is currently wrapped. FALSE otherwise. - */ - public function hasAccount(); - } diff --git a/core/modules/filter/src/Tests/FilterFormTest.php b/core/modules/filter/src/Tests/FilterFormTest.php index 9d0641e..5273346 100644 --- a/core/modules/filter/src/Tests/FilterFormTest.php +++ b/core/modules/filter/src/Tests/FilterFormTest.php @@ -72,7 +72,7 @@ public function testFilterForm() { // @see https://www.drupal.org/node/2387983 \Drupal::service('module_installer')->install(['filter_test_plugin']); // Force rebuild module data. - _system_rebuild_module_data(); + \Drupal::service('extension.list.module')->reset()->listExtensions(); } /** diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 2c2c6b6..2dcbaf0 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -986,6 +986,7 @@ function system_get_info($type, $name = NULL) { * function is no longer used in Drupal core. */ function _system_rebuild_module_data_ensure_required($module, &$modules) { + @trigger_error("_system_rebuild_module_data_ensure_required() is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. This function is no longer used in Drupal core. See https://www.drupal.org/node/2709919", E_USER_DEPRECATED); if (!empty($module->info['required'])) { foreach ($module->info['dependencies'] as $dependency) { $dependency_name = ModuleHandler::parseDependency($dependency)['name']; @@ -1007,7 +1008,8 @@ function _system_rebuild_module_data_ensure_required($module, &$modules) { * * @deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0. * Use \Drupal::service('extension.list.module')->reset()->listExtensions() - * instead. Note: You probably don't need the reset() method. + * instead. Note: You probably don't need the reset() method. See + * https://www.drupal.org/node/2709919. */ function _system_rebuild_module_data() { @trigger_error("_system_rebuild_module_data() is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, you should use \\Drupal::service('extension.list.module')->reset()->listExtensions(). See https://www.drupal.org/node/2709919", E_USER_DEPRECATED); @@ -1019,11 +1021,8 @@ function _system_rebuild_module_data() { * * @return \Drupal\Core\Extension\Extension[] * Array of all available modules and their data. - * - * @deprecated in Drupal 8.4.x and will be removed before Drupal 9.0.0. */ function system_rebuild_module_data() { - @trigger_error("system_rebuild_module_data() is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Instead, you should use \\Drupal::service('extension.list.module')->reset()->listExtensions(). See https://www.drupal.org/node/2709919", E_USER_DEPRECATED); return \Drupal::service('extension.list.module')->reset()->listExtensions(); } diff --git a/core/modules/update/update.module b/core/modules/update/update.module index 32b5b8c..c43d1af 100644 --- a/core/modules/update/update.module +++ b/core/modules/update/update.module @@ -607,7 +607,7 @@ function template_preprocess_update_last_check(&$variables) { * version of Drupal core. * * @see \Drupal\Core\Extension\ExtensionDiscovery - * @see _system_rebuild_module_data() + * @see \Drupal\Core\Extension\ModuleExtensionList */ function update_verify_update_archive($project, $archive_file, $directory) { $errors = []; diff --git a/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php b/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php index 3e4da51..9f57608 100644 --- a/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php +++ b/core/tests/Drupal/Tests/Core/Extension/ExtensionListTest.php @@ -21,6 +21,16 @@ class ExtensionListTest extends UnitTestCase { /** + * @covers ::extensionExists + */ + public function testExtensionExists() { + $test_extension_list = $this->setupTestExtensionList(); + + $this->assertTrue($test_extension_list->extensionExists('test_name')); + $this->assertFalse($test_extension_list->extensionExists('does_not_exist')); + } + + /** * @covers ::getName */ public function testGetNameWithNonExistingExtension() { @@ -31,7 +41,7 @@ public function testGetNameWithNonExistingExtension() { $extension_discovery->scan('test_extension')->willReturn([]); $test_extension_list->setExtensionDiscovery($extension_discovery->reveal()); - $this->setExpectedException(\InvalidArgumentException::class); + $this->setExpectedException(\InvalidArgumentException::class, 'The test_extension test_name does not exist.'); $test_extension_list->getName('test_name'); } @@ -55,7 +65,7 @@ public function testGetExtensionWithNonExistingExtension() { $extension_discovery->scan('test_extension')->willReturn([]); $test_extension_list->setExtensionDiscovery($extension_discovery->reveal()); - $this->setExpectedException(\InvalidArgumentException::class); + $this->setExpectedException(\InvalidArgumentException::class, 'The test_extension test_name does not exist.'); $test_extension_list->getExtension('test_name'); } @@ -99,6 +109,15 @@ public function testGetExtensionInfo() { } /** + * @covers ::getExtensionInfo + */ + public function testGetExtensionInfoException() { + $test_extension_list = $this->setupTestExtensionList(); + $this->setExpectedException(\InvalidArgumentException::class, 'The test_extension test_name does not exist or is not installed.'); + $test_extension_list->getExtensionInfo('test_name'); + } + + /** * @covers ::getAllAvailableInfo */ public function testGetAllAvailableInfo() { @@ -151,6 +170,14 @@ public function testGetPathname() { $this->assertEquals('vfs://drupal_root/example/test_name/test_name.info.yml', $pathname); } + /** + * @covers ::getPathname + */ + public function testGetPathnameException() { + $test_extension_list = $this->setupTestExtensionList(); + $this->setExpectedException(\InvalidArgumentException::class, 'The test_extension does_not_exist does not exist.'); + $test_extension_list->getPathname('does_not_exist'); + } /** * @covers ::setPathname diff --git a/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php b/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php index f17858cf..0e575a0 100644 --- a/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php +++ b/core/tests/Drupal/Tests/Core/Session/AccountProxyTest.php @@ -42,17 +42,6 @@ public function testSetInitialAccountIdException() { $account_proxy->setInitialAccountId(1); } - /** - * @covers ::hasAccount - */ - public function testHasAccount() { - $account_proxy = new AccountProxy(); - $this->assertFalse($account_proxy->hasAccount()); - - $account_proxy->getAccount(); - $this->assertTrue($account_proxy->hasAccount()); - } - } namespace Drupal\Core\Session;