From 974343f33c0ba40155f6eb574f393de2cc868768 Mon Sep 17 00:00:00 2001
From: Igor Biki <ibiki@waterloo.ca>
Date: Mon, 12 Dec 2022 14:45:02 -0500
Subject: [PATCH] ISTWCMS-5925: Adding secondary sort, when created datetime is
 same after the migration.

---
 uw_cfg_common.module | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/uw_cfg_common.module b/uw_cfg_common.module
index d3b0b0a9..5eacc811 100644
--- a/uw_cfg_common.module
+++ b/uw_cfg_common.module
@@ -21,6 +21,8 @@ use Drupal\fillpdf\Form\FillPdfFormForm;
 use Drupal\media_library\MediaLibraryState;
 use Drupal\user\UserInterface;
 use Drupal\uw_cfg_common\Service\UWService;
+use Drupal\views\Plugin\views\query\QueryPluginBase;
+use Drupal\views\ViewExecutable;
 use Drupal\webform\WebformInterface;
 use Drupal\webform\WebformSubmissionStorageInterface;
 
@@ -1603,3 +1605,14 @@ function _uw_cfg_common_allowed_media_types(
     'image' => 'Image',
   ];
 }
+
+/**
+ * Implements hook_views_query_alter().
+ */
+function uw_cfg_common_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
+  // Redirect page default sort updated, added redirect id to sort, on top of
+  // created datetime sort.
+  if ($view->id() === 'redirect') {
+    $query->addOrderBy('redirect', 'rid');
+  }
+}
-- 
GitLab