From 5be2df421d9f890ec068f87087fe8f9c419461cc Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Mon, 7 Oct 2019 14:46:33 +0100
Subject: [PATCH] Issue #2940189 by Vlad Bo, claudiu.cristea, alexpott,
 NightHunterSV, andypost, almaudoh, voleger, Berdir: Deprecate
 system_get_info()

---
 core/includes/install.inc                     |  7 ++--
 .../Core/Menu/Form/MenuLinkDefaultForm.php    |  7 ----
 .../src/Kernel/BlockConfigSchemaTest.php      |  2 +-
 core/modules/ckeditor/ckeditor.module         |  2 +-
 .../help/src/Controller/HelpController.php    | 25 ++++++++++---
 .../help/tests/src/Functional/HelpTest.php    |  3 +-
 core/modules/media/media.install              |  2 +-
 core/modules/quickedit/quickedit.module       |  2 +-
 .../system/src/Controller/AdminController.php | 35 ++++++++++++++++++-
 core/modules/system/system.install            |  4 +--
 core/modules/system/system.module             |  9 ++++-
 .../src/Kernel/System/SystemGetInfoTest.php   |  4 +++
 core/profiles/demo_umami/demo_umami.install   |  2 +-
 .../Core/Theme/ThemeInstallerTest.php         |  4 +--
 14 files changed, 82 insertions(+), 26 deletions(-)

diff --git a/core/includes/install.inc b/core/includes/install.inc
index 2834e918f535..3f2f79b6fc70 100644
--- a/core/includes/install.inc
+++ b/core/includes/install.inc
@@ -109,7 +109,7 @@ function drupal_install_profile_distribution_name() {
   // At all other times, we load the profile via standard methods.
   else {
     $profile = \Drupal::installProfile();
-    $info = system_get_info('module', $profile);
+    $info = \Drupal::service('extension.list.profile')->getExtensionInfo($profile);
   }
   return isset($info['distribution']['name']) ? $info['distribution']['name'] : 'Drupal';
 }
@@ -134,7 +134,7 @@ function drupal_install_profile_distribution_version() {
   // At all other times, we load the profile via standard methods.
   else {
     $profile = \Drupal::installProfile();
-    $info = system_get_info('module', $profile);
+    $info = \Drupal::service('extension.list.profile')->getExtensionInfo($profile);
     return $info['version'];
   }
 }
@@ -1095,7 +1095,8 @@ function drupal_check_module($module) {
  *
  * Note that this function does an expensive file system scan to get info file
  * information for dependencies. If you only need information from the info
- * file itself, use system_get_info().
+ * file itself, use
+ * \Drupal::service('extension.list.profile')->getExtensionInfo().
  *
  * Example of .info.yml file:
  * @code
diff --git a/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php
index eb564ee9ab8a..5aee5cf0f227 100644
--- a/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php
+++ b/core/lib/Drupal/Core/Menu/Form/MenuLinkDefaultForm.php
@@ -49,13 +49,6 @@ class MenuLinkDefaultForm implements MenuLinkFormInterface, ContainerInjectionIn
    */
   protected $moduleHandler;
 
-  /**
-   * The module data from system_get_info().
-   *
-   * @var array
-   */
-  protected $moduleData;
-
   /**
    * Constructs a new \Drupal\Core\Menu\Form\MenuLinkDefaultForm.
    *
diff --git a/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php b/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php
index 2bf41e0f4c02..99854faf4fac 100644
--- a/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php
+++ b/core/modules/block/tests/src/Kernel/BlockConfigSchemaTest.php
@@ -27,7 +27,7 @@ class BlockConfigSchemaTest extends KernelTestBase {
     'forum',
     'node',
     'statistics',
-    // BlockManager->getModuleName() calls system_get_info().
+    // \Drupal\block\Entity\Block->preSave() calls system_region_list().
     'system',
     'taxonomy',
     'user',
diff --git a/core/modules/ckeditor/ckeditor.module b/core/modules/ckeditor/ckeditor.module
index 869c0e916d41..55bbf5b2fb6c 100644
--- a/core/modules/ckeditor/ckeditor.module
+++ b/core/modules/ckeditor/ckeditor.module
@@ -85,7 +85,7 @@ function _ckeditor_theme_css($theme = NULL) {
     $theme = \Drupal::config('system.theme')->get('default');
   }
   if (isset($theme) && $theme_path = drupal_get_path('theme', $theme)) {
-    $info = system_get_info('theme', $theme);
+    $info = \Drupal::service('extension.list.theme')->getExtensionInfo($theme);
     if (isset($info['ckeditor_stylesheets'])) {
       $css = $info['ckeditor_stylesheets'];
       foreach ($css as $key => $url) {
diff --git a/core/modules/help/src/Controller/HelpController.php b/core/modules/help/src/Controller/HelpController.php
index edf8a8a5b734..92d12d6ceba0 100644
--- a/core/modules/help/src/Controller/HelpController.php
+++ b/core/modules/help/src/Controller/HelpController.php
@@ -4,6 +4,7 @@
 
 use Drupal\Core\Cache\CacheableMetadata;
 use Drupal\Core\Controller\ControllerBase;
+use Drupal\Core\Extension\ModuleExtensionList;
 use Drupal\Core\Routing\RouteMatchInterface;
 use Drupal\help\HelpSectionManager;
 use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -28,6 +29,13 @@ class HelpController extends ControllerBase {
    */
   protected $helpManager;
 
+  /**
+   * The module extension list.
+   *
+   * @var \Drupal\Core\Extension\ModuleExtensionList
+   */
+  protected $moduleExtensionList;
+
   /**
    * Creates a new HelpController.
    *
@@ -35,10 +43,18 @@ class HelpController extends ControllerBase {
    *   The current route match.
    * @param \Drupal\help\HelpSectionManager $help_manager
    *   The help section manager.
+   * @param \Drupal\Core\Extension\ModuleExtensionList|null $module_extension_list
+   *   The module extension list. This is left optional for BC reasons, but the
+   *   optional usage is deprecated and will become required in Drupal 9.0.0.
    */
-  public function __construct(RouteMatchInterface $route_match, HelpSectionManager $help_manager) {
+  public function __construct(RouteMatchInterface $route_match, HelpSectionManager $help_manager, ModuleExtensionList $module_extension_list = NULL) {
     $this->routeMatch = $route_match;
     $this->helpManager = $help_manager;
+    if ($module_extension_list === NULL) {
+      @trigger_error('Calling HelpController::__construct() with the $module_extension_list argument is supported in drupal:8.8.0 and will be required before drupal:9.0.0. See https://www.drupal.org/node/2709919.', E_USER_DEPRECATED);
+      $module_extension_list = \Drupal::service('extension.list.module');
+    }
+    $this->moduleExtensionList = $module_extension_list;
   }
 
   /**
@@ -47,7 +63,8 @@ public function __construct(RouteMatchInterface $route_match, HelpSectionManager
   public static function create(ContainerInterface $container) {
     return new static(
       $container->get('current_route_match'),
-      $container->get('plugin.manager.help_section')
+      $container->get('plugin.manager.help_section'),
+      $container->get('extension.list.module')
     );
   }
 
@@ -119,7 +136,7 @@ public function helpPage($name) {
       $module_name = $this->moduleHandler()->getName($name);
       $build['#title'] = $module_name;
 
-      $info = system_get_info('module', $name);
+      $info = $this->moduleExtensionList->getExtensionInfo($name);
       if ($info['package'] === 'Core (Experimental)') {
         $this->messenger()->addWarning($this->t('This module is experimental. <a href=":url">Experimental modules</a> are provided for testing purposes only. Use at your own risk.', [':url' => 'https://www.drupal.org/core/experimental']));
       }
@@ -137,7 +154,7 @@ public function helpPage($name) {
 
       // Only print list of administration pages if the module in question has
       // any such pages associated with it.
-      $admin_tasks = system_get_module_admin_tasks($name, system_get_info('module', $name));
+      $admin_tasks = system_get_module_admin_tasks($name, $info);
       if (!empty($admin_tasks)) {
         $links = [];
         foreach ($admin_tasks as $task) {
diff --git a/core/modules/help/tests/src/Functional/HelpTest.php b/core/modules/help/tests/src/Functional/HelpTest.php
index 8d1e538c176d..608263d4c9dc 100644
--- a/core/modules/help/tests/src/Functional/HelpTest.php
+++ b/core/modules/help/tests/src/Functional/HelpTest.php
@@ -124,7 +124,8 @@ protected function verifyHelp($response = 200) {
       if ($response == 200) {
         $this->assertTitle($name . ' | Drupal', new FormattableMarkup('%module title was displayed', ['%module' => $module]));
         $this->assertEquals($name, $this->cssSelect('h1.page-title')[0]->getText(), "$module heading was displayed");
-        $admin_tasks = system_get_module_admin_tasks($module, system_get_info('module', $module));
+        $info = \Drupal::service('extension.list.module')->getExtensionInfo($module);
+        $admin_tasks = system_get_module_admin_tasks($module, $info);
         if (!empty($admin_tasks)) {
           $this->assertText(t('@module administration pages', ['@module' => $name]));
         }
diff --git a/core/modules/media/media.install b/core/modules/media/media.install
index 25a4f5dfe203..83b6a35c21cd 100644
--- a/core/modules/media/media.install
+++ b/core/modules/media/media.install
@@ -80,7 +80,7 @@ function media_requirements($phase) {
 
     // Prevent installation if the 1.x branch of the contrib module is enabled.
     if (\Drupal::moduleHandler()->moduleExists('media_entity')) {
-      $info = system_get_info('module', 'media_entity');
+      $info = \Drupal::service('extension.list.module')->getExtensionInfo('media_entity');
       if (version_compare($info['version'], '8.x-2') < 0) {
         $requirements['media_module_incompatibility'] = [
           'title' => t('Media'),
diff --git a/core/modules/quickedit/quickedit.module b/core/modules/quickedit/quickedit.module
index fc92d9ca7897..9741006e6195 100644
--- a/core/modules/quickedit/quickedit.module
+++ b/core/modules/quickedit/quickedit.module
@@ -80,7 +80,7 @@ function quickedit_library_info_alter(&$libraries, $extension) {
     // First let the base theme modify the library, then the actual theme.
     $alter_library = function (&$library, $theme) use (&$alter_library) {
       if (!empty($theme) && $theme_path = drupal_get_path('theme', $theme)) {
-        $info = system_get_info('theme', $theme);
+        $info = \Drupal::service('extension.list.theme')->getExtensionInfo($theme);
         // Recurse to process base theme(s) first.
         if (isset($info['base theme'])) {
           $alter_library($library, $info['base theme']);
diff --git a/core/modules/system/src/Controller/AdminController.php b/core/modules/system/src/Controller/AdminController.php
index 3da4b0901dc9..767a8ce2267b 100644
--- a/core/modules/system/src/Controller/AdminController.php
+++ b/core/modules/system/src/Controller/AdminController.php
@@ -3,12 +3,45 @@
 namespace Drupal\system\Controller;
 
 use Drupal\Core\Controller\ControllerBase;
+use Drupal\Core\Extension\ModuleExtensionList;
+use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
  * Controller for admin section.
  */
 class AdminController extends ControllerBase {
 
+  /**
+   * The module extension list.
+   *
+   * @var \Drupal\Core\Extension\ModuleExtensionList
+   */
+  protected $moduleExtensionList;
+
+  /**
+   * AdminController constructor.
+   *
+   * @param \Drupal\Core\Extension\ModuleExtensionList|null $extension_list_module
+   *   The module extension list. This is left optional for BC reasons, but the
+   *   optional usage is deprecated and will become required in Drupal 9.0.0.
+   */
+  public function __construct(ModuleExtensionList $extension_list_module = NULL) {
+    if ($extension_list_module === NULL) {
+      @trigger_error('Calling AdminController::__construct() with the $module_extension_list argument is supported in drupal:8.8.0 and will be required before drupal:9.0.0. See https://www.drupal.org/node/2709919.', E_USER_DEPRECATED);
+      $extension_list_module = \Drupal::service('extension.list.module');
+    }
+    $this->moduleExtensionList = $extension_list_module;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container) {
+    return new static(
+      $container->get('extension.list.module')
+    );
+  }
+
   /**
    * Prints a listing of admin tasks, organized by module.
    *
@@ -16,7 +49,7 @@ class AdminController extends ControllerBase {
    *   A render array containing the listing.
    */
   public function index() {
-    $module_info = system_get_info('module');
+    $module_info = $this->moduleExtensionList->getAllInstalledInfo();
     foreach ($module_info as $module => $info) {
       $module_info[$module] = new \stdClass();
       $module_info[$module]->info = $info;
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index 69433cf8977a..001ddcae8830 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -50,7 +50,7 @@ function system_requirements($phase) {
     // is not running the default installation profile.
     $profile = \Drupal::installProfile();
     if ($profile != 'standard') {
-      $info = system_get_info('module', $profile);
+      $info = \Drupal::service('extension.list.module')->getExtensionInfo($profile);
       $requirements['install_profile'] = [
         'title' => t('Installation profile'),
         'value' => t('%profile_name (%profile-%version)', [
@@ -67,7 +67,7 @@ function system_requirements($phase) {
     $experimental = [];
     $enabled_modules = \Drupal::moduleHandler()->getModuleList();
     foreach ($enabled_modules as $module => $data) {
-      $info = system_get_info('module', $module);
+      $info = \Drupal::service('extension.list.module')->getExtensionInfo($module);
       if (isset($info['package']) && $info['package'] === 'Core (Experimental)') {
         $experimental[$module] = $info['name'];
       }
diff --git a/core/modules/system/system.module b/core/modules/system/system.module
index b65838f376ce..b6dc4fb101c2 100644
--- a/core/modules/system/system.module
+++ b/core/modules/system/system.module
@@ -979,10 +979,16 @@ function system_check_directory($form_element, FormStateInterface $form_state) {
  *   information for $name, if given. If no records are available, an empty
  *   array is returned.
  *
+ * @deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use
+ *   \Drupal::service('extension.list.$type')->getExtensionInfo() or
+ *   \Drupal::service('extension.list.$type')->getAllInstalledInfo() instead.
+ *
+ * @see https://www.drupal.org/node/2709919
  * @see \Drupal\Core\Extension\ModuleExtensionList::getList()
  * @see \Drupal\Core\Extension\ThemeExtensionList
  */
 function system_get_info($type, $name = NULL) {
+  @trigger_error("system_get_info() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal::service('extension.list.$type')->getExtensionInfo() or \Drupal::service('extension.list.$type')->getAllInstalledInfo() instead. See https://www.drupal.org/node/2709919", E_USER_DEPRECATED);
   /** @var \Drupal\Core\Extension\ExtensionList $extension_list */
   $extension_list = \Drupal::service('extension.list.' . $type);
   if (isset($name)) {
@@ -1168,7 +1174,8 @@ function system_admin_compact_mode() {
  * @param string $module
  *   Module name.
  * @param array $info
- *   The module's information, as provided by system_get_info().
+ *   The module's information, as provided by
+ *   \Drupal::service('extension.list.module')->getExtensionInfo().
  *
  * @return array
  *   An array of task links.
diff --git a/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php b/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php
index cd42fa48707d..881005b02686 100644
--- a/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php
+++ b/core/modules/system/tests/src/Kernel/System/SystemGetInfoTest.php
@@ -8,6 +8,7 @@
  * Tests system_get_info().
  *
  * @group system
+ * @group legacy
  */
 class SystemGetInfoTest extends KernelTestBase {
 
@@ -15,6 +16,9 @@ class SystemGetInfoTest extends KernelTestBase {
 
   /**
    * Tests system_get_info().
+   *
+   * @expectedDeprecation system_get_info() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal::service('extension.list.module')->getExtensionInfo() or \Drupal::service('extension.list.module')->getAllInstalledInfo() instead. See https://www.drupal.org/node/2709919
+   * @expectedDeprecation system_get_info() is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. Use \Drupal::service('extension.list.theme')->getExtensionInfo() or \Drupal::service('extension.list.theme')->getAllInstalledInfo() instead. See https://www.drupal.org/node/2709919
    */
   public function testSystemGetInfo() {
     $system_module_info = system_get_info('module', 'system');
diff --git a/core/profiles/demo_umami/demo_umami.install b/core/profiles/demo_umami/demo_umami.install
index 37025e082684..4137ca2ef37f 100644
--- a/core/profiles/demo_umami/demo_umami.install
+++ b/core/profiles/demo_umami/demo_umami.install
@@ -15,7 +15,7 @@ function demo_umami_requirements($phase) {
   $requirements = [];
   if ($phase == 'runtime') {
     $profile = \Drupal::installProfile();
-    $info = system_get_info('module', $profile);
+    $info = \Drupal::service('extension.list.profile')->getExtensionInfo($profile);
     $requirements['experimental_profile_used'] = [
       'title' => t('Experimental installation profile used'),
       'value' => $info['name'],
diff --git a/core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php b/core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php
index f6e8ee7136fd..d625c2d9f68e 100644
--- a/core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Theme/ThemeInstallerTest.php
@@ -321,7 +321,7 @@ public function testThemeInfoAlter() {
     // Legacy assertions.
     // @todo Remove once theme initialization/info has been modernized.
     // @see https://www.drupal.org/node/2228093
-    $info = system_get_info('theme', $name);
+    $info = \Drupal::service('extension.list.theme')->getExtensionInfo($name);
     $this->assertTrue(isset($info['regions']['test_region']));
     $regions = system_region_list($name);
     $this->assertTrue(isset($regions['test_region']));
@@ -337,7 +337,7 @@ public function testThemeInfoAlter() {
     // Legacy assertions.
     // @todo Remove once theme initialization/info has been modernized.
     // @see https://www.drupal.org/node/2228093
-    $info = system_get_info('theme', $name);
+    $info = \Drupal::service('extension.list.theme')->getExtensionInfo($name);
     $this->assertFalse(isset($info['regions']['test_region']));
     $regions = system_region_list($name);
     $this->assertFalse(isset($regions['test_region']));
-- 
GitLab