From 9e2c8f7e4f23a448b58779f17bc841f8f736ab45 Mon Sep 17 00:00:00 2001
From: rahul_ <rahul_gupta@3278723.no-reply.drupal.org>
Date: Thu, 18 Aug 2022 20:23:24 +0000
Subject: [PATCH] Issue #3303113 by phenaproxima, rahul_, rkoller, tedbow: Add
 bullet points to the modules listed on the ready to update pages warning
 message

---
 .../src/Form/UpdateReady.php                  | 30 +++++++++++++++----
 .../tests/src/Functional/UpdaterFormTest.php  | 13 +++++---
 src/Form/UpdateReady.php                      | 30 +++++++++++++++----
 tests/src/Functional/UpdaterFormTest.php      | 13 ++++++--
 4 files changed, 67 insertions(+), 19 deletions(-)

diff --git a/automatic_updates_extensions/src/Form/UpdateReady.php b/automatic_updates_extensions/src/Form/UpdateReady.php
index 35f27ea5ec..bc0381ac4d 100644
--- a/automatic_updates_extensions/src/Form/UpdateReady.php
+++ b/automatic_updates_extensions/src/Form/UpdateReady.php
@@ -10,6 +10,7 @@ use Drupal\Core\Batch\BatchBuilder;
 use Drupal\Core\Extension\ModuleExtensionList;
 use Drupal\Core\Form\FormBase;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Render\RendererInterface;
 use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\Core\State\StateInterface;
 use Drupal\package_manager\Exception\StageException;
@@ -52,6 +53,13 @@ final class UpdateReady extends FormBase {
    */
   protected $stagedDatabaseUpdateValidator;
 
+  /**
+   * The renderer service.
+   *
+   * @var \Drupal\Core\Render\RendererInterface
+   */
+  protected $renderer;
+
   /**
    * Constructs a new UpdateReady object.
    *
@@ -65,13 +73,16 @@ final class UpdateReady extends FormBase {
    *   The module list service.
    * @param \Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator $staged_database_update_validator
    *   The staged database update validator service.
+   * @param \Drupal\Core\Render\RendererInterface $renderer
+   *   The renderer service.
    */
-  public function __construct(ExtensionUpdater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list, StagedDatabaseUpdateValidator $staged_database_update_validator) {
+  public function __construct(ExtensionUpdater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list, StagedDatabaseUpdateValidator $staged_database_update_validator, RendererInterface $renderer) {
     $this->updater = $updater;
     $this->setMessenger($messenger);
     $this->state = $state;
     $this->moduleList = $module_list;
     $this->stagedDatabaseUpdateValidator = $staged_database_update_validator;
+    $this->renderer = $renderer;
   }
 
   /**
@@ -90,7 +101,8 @@ final class UpdateReady extends FormBase {
       $container->get('messenger'),
       $container->get('state'),
       $container->get('extension.list.module'),
-      $container->get('automatic_updates.validator.staged_database_updates')
+      $container->get('automatic_updates.validator.staged_database_updates'),
+      $container->get('renderer')
     );
   }
 
@@ -113,10 +125,16 @@ final class UpdateReady extends FormBase {
     // changes have been applied.
     $pending_updates = $this->stagedDatabaseUpdateValidator->getExtensionsWithDatabaseUpdates($this->updater);
     if ($pending_updates) {
-      $messages[MessengerInterface::TYPE_WARNING][] = $this->t('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.');
-      foreach ($pending_updates as $pending_update) {
-        $messages[MessengerInterface::TYPE_WARNING][] = $pending_update;
-      }
+      natcasesort($pending_updates);
+      $message_item_list = [
+        '#theme' => 'item_list',
+        '#prefix' => '<p>' . $this->t('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.') . '</p>',
+        '#items' => $pending_updates,
+        '#context' => [
+          'list_style' => 'automatic-updates-extensions__pending-database-updates',
+        ],
+      ];
+      $messages[MessengerInterface::TYPE_WARNING][] = $this->renderer->renderRoot($message_item_list);
     }
 
     // Don't set any messages if the form has been submitted, because we don't
diff --git a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php
index 0e7b82b8ea..b318ede904 100644
--- a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php
+++ b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php
@@ -190,10 +190,15 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
     $this->assertUpdateStagedTimes(1);
     // Confirm that the site was put into maintenance mode if needed.
     $this->assertSame($state->get('system.maintenance_mode'), $maintenance_mode_on);
-    $possible_update_message = 'Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.';
-    $assert_session->pageTextContains($possible_update_message);
-    $assert_session->pageTextContainsOnce('System');
-    $assert_session->pageTextContainsOnce('Automatic Updates Theme With Updates');
+
+    // Ensure that a list of pending database updates is visible, along with a
+    // short explanation, in the warning messages.
+    $warning_messages = $assert_session->elementExists('xpath', '//div[@data-drupal-messages]//div[@aria-label="Warning message"]');
+    $this->assertStringContainsString('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.', $warning_messages->getText());
+    $pending_updates = $warning_messages->findAll('css', 'ul.item-list__automatic-updates-extensions__pending-database-updates li');
+    $this->assertCount(2, $pending_updates);
+    $this->assertSame('Automatic Updates Theme With Updates', $pending_updates[0]->getText());
+    $this->assertSame('System', $pending_updates[1]->getText());
 
     $page->pressButton('Continue');
     $this->checkForMetaRefresh();
diff --git a/src/Form/UpdateReady.php b/src/Form/UpdateReady.php
index 2fa0ca77f4..4b07f27778 100644
--- a/src/Form/UpdateReady.php
+++ b/src/Form/UpdateReady.php
@@ -10,6 +10,7 @@ use Drupal\Core\Extension\ModuleExtensionList;
 use Drupal\Core\Form\FormBase;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Messenger\MessengerInterface;
+use Drupal\Core\Render\RendererInterface;
 use Drupal\Core\State\StateInterface;
 use Drupal\package_manager\Exception\StageException;
 use Drupal\package_manager\Exception\StageOwnershipException;
@@ -51,6 +52,13 @@ final class UpdateReady extends FormBase {
    */
   protected $stagedDatabaseUpdateValidator;
 
+  /**
+   * The renderer service.
+   *
+   * @var \Drupal\Core\Render\RendererInterface
+   */
+  protected $renderer;
+
   /**
    * Constructs a new UpdateReady object.
    *
@@ -64,13 +72,16 @@ final class UpdateReady extends FormBase {
    *   The module list service.
    * @param \Drupal\automatic_updates\Validator\StagedDatabaseUpdateValidator $staged_database_update_validator
    *   The staged database update validator service.
+   * @param \Drupal\Core\Render\RendererInterface $renderer
+   *   The renderer service.
    */
-  public function __construct(Updater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list, StagedDatabaseUpdateValidator $staged_database_update_validator) {
+  public function __construct(Updater $updater, MessengerInterface $messenger, StateInterface $state, ModuleExtensionList $module_list, StagedDatabaseUpdateValidator $staged_database_update_validator, RendererInterface $renderer) {
     $this->updater = $updater;
     $this->setMessenger($messenger);
     $this->state = $state;
     $this->moduleList = $module_list;
     $this->stagedDatabaseUpdateValidator = $staged_database_update_validator;
+    $this->renderer = $renderer;
   }
 
   /**
@@ -89,7 +100,8 @@ final class UpdateReady extends FormBase {
       $container->get('messenger'),
       $container->get('state'),
       $container->get('extension.list.module'),
-      $container->get('automatic_updates.validator.staged_database_updates')
+      $container->get('automatic_updates.validator.staged_database_updates'),
+      $container->get('renderer')
     );
   }
 
@@ -112,10 +124,16 @@ final class UpdateReady extends FormBase {
     // the staged changes have been applied.
     $pending_updates = $this->stagedDatabaseUpdateValidator->getExtensionsWithDatabaseUpdates($this->updater);
     if ($pending_updates) {
-      $messages[MessengerInterface::TYPE_WARNING][] = $this->t('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.');
-      foreach ($pending_updates as $pending_update) {
-        $messages[MessengerInterface::TYPE_WARNING][] = $pending_update;
-      }
+      natcasesort($pending_updates);
+      $message_item_list = [
+        '#theme' => 'item_list',
+        '#prefix' => '<p>' . $this->t('Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.') . '</p>',
+        '#items' => $pending_updates,
+        '#context' => [
+          'list_style' => 'automatic-updates__pending-database-updates',
+        ],
+      ];
+      $messages[MessengerInterface::TYPE_WARNING][] = $this->renderer->renderRoot($message_item_list);
     }
 
     try {
diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php
index d037cc518d..d71b9f14f9 100644
--- a/tests/src/Functional/UpdaterFormTest.php
+++ b/tests/src/Functional/UpdaterFormTest.php
@@ -483,10 +483,17 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
     // changes have been applied, we should be redirected to update.php, where
     // neither warning should be visible.
     $assert_session->pageTextNotContains(reset($messages));
+
+    // Ensure that a list of pending database updates is visible, along with a
+    // short explanation, in the warning messages.
     $possible_update_message = 'Possible database updates were detected in the following extensions; you may be redirected to the database update page in order to complete the update process.';
-    $assert_session->pageTextContains($possible_update_message);
-    $assert_session->pageTextContains('System');
-    $assert_session->pageTextContainsOnce('Automatic Updates Theme With Updates');
+    $warning_messages = $assert_session->elementExists('xpath', '//div[@data-drupal-messages]//div[@aria-label="Warning message"]');
+    $this->assertStringContainsString($possible_update_message, $warning_messages->getText());
+    $pending_updates = $warning_messages->findAll('css', 'ul.item-list__automatic-updates__pending-database-updates li');
+    $this->assertCount(2, $pending_updates);
+    $this->assertSame('Automatic Updates Theme With Updates', $pending_updates[0]->getText());
+    $this->assertSame('System', $pending_updates[1]->getText());
+
     if ($maintenance_mode_on === TRUE) {
       $assert_session->fieldNotExists('maintenance_mode');
     }
-- 
GitLab