From 5e17b213ea3d3ebc8fa598bf6740c1ea1d8dc9fa Mon Sep 17 00:00:00 2001
From: Priti Kelaskar <33161-pritimhjn@users.noreply.drupalcode.org>
Date: Tue, 10 Dec 2024 08:24:08 +0000
Subject: [PATCH 1/2] Update 3 files

- /src/Controller/SitewideAlertController.php
- /src/Form/SitewideAlertRevisionDeleteForm.php
- /src/Form/SitewideAlertRevisionRevertForm.php
---
 src/Controller/SitewideAlertController.php   | 13 ++++++++-----
 src/Form/SitewideAlertRevisionDeleteForm.php |  6 +++---
 src/Form/SitewideAlertRevisionRevertForm.php |  6 +++---
 3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/Controller/SitewideAlertController.php b/src/Controller/SitewideAlertController.php
index 07247ea..4b8e2df 100644
--- a/src/Controller/SitewideAlertController.php
+++ b/src/Controller/SitewideAlertController.php
@@ -62,8 +62,8 @@ class SitewideAlertController extends ControllerBase implements ContainerInjecti
    * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
    */
   public function revisionShow(int $sitewide_alert_revision): array {
-    $sitewide_alert = $this->entityTypeManager()->getStorage('sitewide_alert')
-      ->loadRevision($sitewide_alert_revision);
+    /** @var \Drupal\Core\Entity\RevisionableStorageInterface $sitewide_alert_storage */
+    $sitewide_alert_storage = $this->entityTypeManager()->getStorage('sitewide_alert');
     return $this
       ->entityTypeManager()
       ->getViewBuilder('sitewide_alert')
@@ -83,8 +83,9 @@ class SitewideAlertController extends ControllerBase implements ContainerInjecti
    * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
    */
   public function revisionPageTitle(int $sitewide_alert_revision): TranslatableMarkup {
-    $sitewide_alert = $this->entityTypeManager()->getStorage('sitewide_alert')
-      ->loadRevision($sitewide_alert_revision);
+    /** @var \Drupal\Core\Entity\RevisionableStorageInterface $sitewide_alert_storage */
+    $sitewide_alert_storage = $this->entityTypeManager()->getStorage('sitewide_alert');
+    $sitewide_alert = $sitewide_alert_storage->loadRevision($sitewide_alert_revision);
     return $this->t('Revision of %title from %date', [
       '%title' => $sitewide_alert->label(),
       '%date' => $this->dateFormatter->format($sitewide_alert->getRevisionCreationTime()),
@@ -133,9 +134,11 @@ class SitewideAlertController extends ControllerBase implements ContainerInjecti
 
     $latest_revision = TRUE;
 
+    /** @var \Drupal\Core\Entity\RevisionableStorageInterface $entity_storage */
+    $entity_storage = $this->entityTypeManager()->getStorage('sitewide_alert');
     foreach (array_reverse($vids) as $vid) {
       /** @var \Drupal\sitewide_alert\Entity\SitewideAlertInterface $revision */
-      $revision = $sitewide_alert_storage->loadRevision($vid);
+      $revision = $entity_storage->loadRevision($vid);
       // Only show revisions that are affected by the language that is being
       // displayed.
       if ($revision->hasTranslation($langcode) && $revision->getTranslation($langcode)->isRevisionTranslationAffected()) {
diff --git a/src/Form/SitewideAlertRevisionDeleteForm.php b/src/Form/SitewideAlertRevisionDeleteForm.php
index cf561d8..7682800 100644
--- a/src/Form/SitewideAlertRevisionDeleteForm.php
+++ b/src/Form/SitewideAlertRevisionDeleteForm.php
@@ -6,7 +6,7 @@ namespace Drupal\sitewide_alert\Form;
 
 use Drupal\Core\Database\Connection;
 use Drupal\Core\Datetime\DateFormatterInterface;
-use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Entity\RevisionableStorageInterface;
 use Drupal\Core\Form\ConfirmFormBase;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\StringTranslation\TranslatableMarkup;
@@ -31,7 +31,7 @@ class SitewideAlertRevisionDeleteForm extends ConfirmFormBase {
   /**
    * Constructs a new SitewideAlertRevisionDeleteForm.
    *
-   * @param \Drupal\Core\Entity\EntityStorageInterface $sitewideAlertStorage
+   * @param \Drupal\Core\Entity\RevisionableStorageInterface $sitewideAlertStorage
    *   The entity storage.
    * @param \Drupal\Core\Database\Connection $connection
    *   The database connection.
@@ -39,7 +39,7 @@ class SitewideAlertRevisionDeleteForm extends ConfirmFormBase {
    *   Drupal's date formatter.
    */
   public function __construct(
-    protected EntityStorageInterface $sitewideAlertStorage,
+    protected RevisionableStorageInterface $sitewideAlertStorage,
     protected Connection $connection,
     protected DateFormatterInterface $dateFormatter,
   ) {
diff --git a/src/Form/SitewideAlertRevisionRevertForm.php b/src/Form/SitewideAlertRevisionRevertForm.php
index ac79d21..4c0fcfc 100644
--- a/src/Form/SitewideAlertRevisionRevertForm.php
+++ b/src/Form/SitewideAlertRevisionRevertForm.php
@@ -6,7 +6,7 @@ namespace Drupal\sitewide_alert\Form;
 
 use Drupal\Component\Datetime\TimeInterface;
 use Drupal\Core\Datetime\DateFormatterInterface;
-use Drupal\Core\Entity\EntityStorageInterface;
+use Drupal\Core\Entity\RevisionableStorageInterface;
 use Drupal\Core\Form\ConfirmFormBase;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\StringTranslation\TranslatableMarkup;
@@ -31,7 +31,7 @@ class SitewideAlertRevisionRevertForm extends ConfirmFormBase {
   /**
    * Constructs a new SitewideAlertRevisionRevertForm.
    *
-   * @param \Drupal\Core\Entity\EntityStorageInterface $sitewideAlertStorage
+   * @param \Drupal\Core\Entity\RevisionableStorageInterface $sitewideAlertStorage
    *   The Sitewide Alert storage.
    * @param \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter
    *   The date formatter service.
@@ -39,7 +39,7 @@ class SitewideAlertRevisionRevertForm extends ConfirmFormBase {
    *   The time service.
    */
   public function __construct(
-    protected EntityStorageInterface $sitewideAlertStorage,
+    protected RevisionableStorageInterface $sitewideAlertStorage,
     protected DateFormatterInterface $dateFormatter,
     protected TimeInterface $time,
   ) {
-- 
GitLab


From 2f68fc7759099fba5518d74ce29f10ee385a0e4c Mon Sep 17 00:00:00 2001
From: Stephen Mustgrave <smustgrave@gmail.com>
Date: Sat, 28 Dec 2024 12:50:23 -0500
Subject: [PATCH 2/2] Pipeline fix

---
 src/Controller/SitewideAlertController.php  | 2 +-
 src/Controller/SitewideAlertsController.php | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/Controller/SitewideAlertController.php b/src/Controller/SitewideAlertController.php
index 4b8e2df..4f1612b 100644
--- a/src/Controller/SitewideAlertController.php
+++ b/src/Controller/SitewideAlertController.php
@@ -67,7 +67,7 @@ class SitewideAlertController extends ControllerBase implements ContainerInjecti
     return $this
       ->entityTypeManager()
       ->getViewBuilder('sitewide_alert')
-      ->view($sitewide_alert);
+      ->view($sitewide_alert_storage);
   }
 
   /**
diff --git a/src/Controller/SitewideAlertsController.php b/src/Controller/SitewideAlertsController.php
index 1511e21..2c0dc47 100644
--- a/src/Controller/SitewideAlertsController.php
+++ b/src/Controller/SitewideAlertsController.php
@@ -6,6 +6,7 @@ use Drupal\Core\Cache\CacheableJsonResponse;
 use Drupal\Core\Cache\CacheableMetadata;
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Controller\ControllerBase;
+use Drupal\Core\PageCache\ResponsePolicy\KillSwitch;
 use Drupal\Core\Render\RendererInterface;
 use Drupal\sitewide_alert\SitewideAlertManager;
 use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -25,11 +26,14 @@ class SitewideAlertsController extends ControllerBase {
    *   The sitewide alert manager.
    * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
    *   The config factory service.
+   * @param \Drupal\Core\PageCache\ResponsePolicy\KillSwitch $killSwitch
+   *   The page cache disabling policy.
    */
   public function __construct(
     protected RendererInterface $renderer,
     protected SitewideAlertManager $sitewideAlertManager,
     ConfigFactoryInterface $configFactory,
+    protected KillSwitch $killSwitch,
   ) {
     $this->configFactory = $configFactory;
   }
@@ -41,7 +45,8 @@ class SitewideAlertsController extends ControllerBase {
     return new static(
       $container->get('renderer'),
       $container->get('sitewide_alert.sitewide_alert_manager'),
-      $container->get('config.factory')
+      $container->get('config.factory'),
+      $container->get('page_cache_kill_switch')
     );
   }
 
@@ -114,7 +119,7 @@ class SitewideAlertsController extends ControllerBase {
     // https://www.drupal.org/project/drupal/issues/2835068#comment-13944070
     // @todo Remove once upstream page_cache issue has been addressed.
     if ($this->configFactory->get('system.performance')->get('cache.page.max_age') === 0) {
-      \Drupal::service('page_cache_kill_switch')->trigger();
+      $this->killSwitch->trigger();
     }
 
     return $response;
-- 
GitLab