From 16f9ca27af1a8f00d9da72744b38ddb632f7711a Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Wed, 28 Jul 2021 13:54:02 +0100
Subject: [PATCH] Issue #778346 by vsujeetkumar, xjm, dhirendra.mishra,
 pillarsdotnet, sudiptadas19, cwgordon7, daffie, quietone:
 system_sort_modules_by_info_name() is misnamed

---
 .../system/src/Controller/AdminController.php |  2 +-
 .../src/Controller/SystemController.php       |  2 +-
 .../system/src/Form/ModulesListForm.php       |  2 +-
 .../system/src/Form/ModulesUninstallForm.php  |  2 +-
 core/modules/system/system.module             | 10 +++++-
 .../src/Kernel/SystemDeprecationTest.php      | 31 +++++++++++++++++++
 6 files changed, 44 insertions(+), 5 deletions(-)
 create mode 100644 core/modules/system/tests/src/Kernel/SystemDeprecationTest.php

diff --git a/core/modules/system/src/Controller/AdminController.php b/core/modules/system/src/Controller/AdminController.php
index 2a88b1102509..90b2d1160f54 100644
--- a/core/modules/system/src/Controller/AdminController.php
+++ b/core/modules/system/src/Controller/AdminController.php
@@ -50,7 +50,7 @@ public function index() {
       $module_info[$module]->info = $info;
     }
 
-    uasort($module_info, 'system_sort_modules_by_info_name');
+    uasort($module_info, 'system_sort_by_info_name');
     $menu_items = [];
 
     foreach ($module_info as $module => $info) {
diff --git a/core/modules/system/src/Controller/SystemController.php b/core/modules/system/src/Controller/SystemController.php
index f1f765d71c02..848af4a8d3de 100644
--- a/core/modules/system/src/Controller/SystemController.php
+++ b/core/modules/system/src/Controller/SystemController.php
@@ -203,7 +203,7 @@ public function themesPage() {
     $config = $this->config('system.theme');
     // Get all available themes.
     $themes = $this->themeHandler->rebuildThemeData();
-    uasort($themes, 'system_sort_modules_by_info_name');
+    uasort($themes, 'system_sort_by_info_name');
 
     $theme_default = $config->get('default');
     $theme_groups = ['installed' => [], 'uninstalled' => []];
diff --git a/core/modules/system/src/Form/ModulesListForm.php b/core/modules/system/src/Form/ModulesListForm.php
index cf84a71a2cbd..58bf8b6b4de6 100644
--- a/core/modules/system/src/Form/ModulesListForm.php
+++ b/core/modules/system/src/Form/ModulesListForm.php
@@ -170,7 +170,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
       // The module list needs to be reset so that it can re-scan and include
       // any new modules that may have been added directly into the filesystem.
       $modules = $this->moduleExtensionList->reset()->getList();
-      uasort($modules, 'system_sort_modules_by_info_name');
+      uasort($modules, 'system_sort_by_info_name');
     }
     catch (InfoParserException $e) {
       $this->messenger()->addError($this->t('Modules could not be listed due to an error: %error', ['%error' => $e->getMessage()]));
diff --git a/core/modules/system/src/Form/ModulesUninstallForm.php b/core/modules/system/src/Form/ModulesUninstallForm.php
index 3d2c70b61c87..0b4374037641 100644
--- a/core/modules/system/src/Form/ModulesUninstallForm.php
+++ b/core/modules/system/src/Form/ModulesUninstallForm.php
@@ -144,7 +144,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
     }
 
     // Sort all modules by their name.
-    uasort($uninstallable, 'system_sort_modules_by_info_name');
+    uasort($uninstallable, 'system_sort_by_info_name');
     $validation_reasons = $this->moduleInstaller->validateUninstall(array_keys($uninstallable));
 
     $form['uninstall'] = ['#tree' => TRUE];
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index 0edbe43b7709..bbc0e1fcbf02 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -893,6 +893,14 @@ function system_region_list($theme, $show = REGIONS_ALL) {
  * Array sorting callback; sorts modules by their name.
  */
 function system_sort_modules_by_info_name($a, $b) {
+  @trigger_error('system_sort_modules_by_info_name() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Implement system_sort_by_info_name() instead. See https://www.drupal.org/node/3225624', E_USER_DEPRECATED);
+  return system_sort_by_info_name($a, $b);
+}
+
+/**
+ * Array sorting callback; sorts modules by their name.
+ */
+function system_sort_by_info_name($a, $b) {
   return strcasecmp($a->info['name'], $b->info['name']);
 }
 
@@ -902,7 +910,7 @@ function system_sort_modules_by_info_name($a, $b) {
  * Callback for uasort() within
  * \Drupal\system\Controller\SystemController::themesPage().
  *
- * @see system_sort_modules_by_info_name()
+ * @see system_sort_by_info_name()
  */
 function system_sort_themes($a, $b) {
   if ($a->is_default) {
diff --git a/core/modules/system/tests/src/Kernel/SystemDeprecationTest.php b/core/modules/system/tests/src/Kernel/SystemDeprecationTest.php
new file mode 100644
index 000000000000..991c5122434d
--- /dev/null
+++ b/core/modules/system/tests/src/Kernel/SystemDeprecationTest.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Drupal\Tests\system\Kernel;
+
+use Drupal\KernelTests\KernelTestBase;
+
+/**
+ * @group system
+ * @group legacy
+ */
+class SystemDeprecationTest extends KernelTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected static $modules = ['system', 'user'];
+
+  /**
+   * @see system_sort_modules_by_info_name()
+   */
+  public function testSystemSortModulesByInfoName() {
+    $module_info = [];
+    foreach (\Drupal::service('extension.list.module')->getAllInstalledInfo() as $module => $info) {
+      $module_info[$module] = new \stdClass();
+      $module_info[$module]->info = $info;
+    }
+    $this->expectDeprecation('system_sort_modules_by_info_name() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0. Implement system_sort_by_info_name() instead. See https://www.drupal.org/node/3225624');
+    uasort($module_info, 'system_sort_modules_by_info_name');
+  }
+
+}
-- 
GitLab