diff --git a/automatic_updates_extensions/src/Form/UpdateReady.php b/automatic_updates_extensions/src/Form/UpdateReady.php index 35f27ea5ec9463e8185869274d813cb8af4234ca..bc0381ac4dd0d581ad369e1f06d27ded2d0434e4 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 0e7b82b8eac5d69159333df00220293cfef6437f..b318ede904ddd8101539060aac825a730e930e37 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 2fa0ca77f4f09ef867211fd33e4ef1c770aeb97d..4b07f27778fb1ba7100e5c26b2c46b0302accb48 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 d037cc518dd7cf327f655295dd2c1b3f235a0dc8..d71b9f14f9b39163cbb1f9b5964cb19455e4d569 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'); }