From 883454516ae31eb15139c26290b4684e25b0a364 Mon Sep 17 00:00:00 2001
From: "Theresa.Grannum" <theresa.grannum@3688861.no-reply.drupal.org>
Date: Wed, 29 Jun 2022 17:27:09 +0000
Subject: [PATCH] Issue #3277815 by Theresa.Grannum, tedbow, Shiraz Dindar,
 phenaproxima: Update Extensions tab needs link to check for updates

---
 .../src/Form/UpdaterForm.php                  | 20 +++++++++++++++++--
 .../tests/src/Functional/UpdaterFormTest.php  | 14 ++++++++++---
 2 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/automatic_updates_extensions/src/Form/UpdaterForm.php b/automatic_updates_extensions/src/Form/UpdaterForm.php
index f53a164f1b..7b73ad19b8 100644
--- a/automatic_updates_extensions/src/Form/UpdaterForm.php
+++ b/automatic_updates_extensions/src/Form/UpdaterForm.php
@@ -9,6 +9,7 @@ use Drupal\automatic_updates_extensions\ExtensionUpdater;
 use Drupal\Core\Batch\BatchBuilder;
 use Drupal\Core\Form\FormBase;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\State\StateInterface;
 use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\Core\Render\RendererInterface;
 use Drupal\Core\Url;
@@ -41,6 +42,13 @@ final class UpdaterForm extends FormBase {
    */
   private $eventDispatcher;
 
+  /**
+   * The state service.
+   *
+   * @var \Drupal\Core\State\StateInterface
+   */
+  private $state;
+
   /**
    * The renderer service.
    *
@@ -55,7 +63,8 @@ final class UpdaterForm extends FormBase {
     return new static(
       $container->get('automatic_updates_extensions.updater'),
       $container->get('event_dispatcher'),
-      $container->get('renderer')
+      $container->get('renderer'),
+      $container->get('state')
     );
   }
 
@@ -68,11 +77,14 @@ final class UpdaterForm extends FormBase {
    *   The extension event dispatcher service.
    * @param \Drupal\Core\Render\RendererInterface $renderer
    *   The renderer service.
+   * @param \Drupal\Core\State\StateInterface $state
+   *   The state service.
    */
-  public function __construct(ExtensionUpdater $extension_updater, EventDispatcherInterface $event_dispatcher, RendererInterface $renderer) {
+  public function __construct(ExtensionUpdater $extension_updater, EventDispatcherInterface $event_dispatcher, RendererInterface $renderer, StateInterface $state) {
     $this->extensionUpdater = $extension_updater;
     $this->eventDispatcher = $event_dispatcher;
     $this->renderer = $renderer;
+    $this->state = $state;
   }
 
   /**
@@ -141,6 +153,10 @@ final class UpdaterForm extends FormBase {
       $form['actions'] = $this->actions($form_state);
     }
 
+    $form['last_check'] = [
+      '#theme' => 'update_last_check',
+      '#last' => $this->state->get('update.last_check', 0),
+    ];
     return $form;
   }
 
diff --git a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php
index eccf389f62..1e7e9fd9cc 100644
--- a/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php
+++ b/automatic_updates_extensions/tests/src/Functional/UpdaterFormTest.php
@@ -234,13 +234,12 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
     $user = $this->createUser(['administer site configuration']);
     $this->drupalLogin($user);
     $this->setProjectInstalledVersion(['semver_test' => '8.1.0']);
-    $this->checkForUpdates();
     $this->drupalGet('admin/reports/updates/automatic-update-extensions');
     $assert->pageTextContains('Access Denied');
     $assert->pageTextNotContains('Automatic Updates Form');
-    $user = $this->createUser(['administer software updates']);
+    $user = $this->createUser(['administer software updates', 'administer site configuration']);
     $this->drupalLogin($user);
-    $this->drupalGet('admin/reports/updates/automatic-update-extensions');
+    $this->checkForUpdates();
     $this->assertTableShowsUpdates('Semver Test', '8.1.0', '8.1.1');
     $assert->pageTextContains('Automatic Updates Form');
     $assert->buttonExists('Update');
@@ -262,6 +261,15 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase {
     $this->assertNoUpdates();
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  protected function checkForUpdates(): void {
+    $this->drupalGet('/admin/modules/automatic-update-extensions');
+    $this->clickLink('Check manually');
+    $this->checkForMetaRefresh();
+  }
+
   /**
    * Test the form for errors.
    */
-- 
GitLab