SearchKit - Ensure id & name are defined when loading saved searches
authorColeman Watts <coleman@civicrm.org>
Fri, 9 Dec 2022 19:30:38 +0000 (14:30 -0500)
committerColeman Watts <coleman@civicrm.org>
Fri, 9 Dec 2022 19:30:38 +0000 (14:30 -0500)
Civi/Api4/Generic/Traits/SavedSearchInspectorTrait.php

index f40b384690f60509650cdd5c2800372bfd2ece69..1e2b87ce66eb7af805d78e66a0ca8a6624cd51af 100644 (file)
@@ -56,7 +56,12 @@ trait SavedSearchInspectorTrait {
         ->execute()->single();
     }
     if (is_array($this->savedSearch)) {
-      $this->savedSearch += ['api_params' => []];
+      // Ensure array keys are always defined even for unsaved "preview" mode
+      $this->savedSearch += [
+        'id' => NULL,
+        'name' => NULL,
+        'api_params' => [],
+      ];
       $this->savedSearch['api_params'] += ['version' => 4, 'select' => [], 'where' => []];
     }
     $this->_apiParams = ($this->savedSearch['api_params'] ?? []) + ['select' => [], 'where' => []];
@@ -83,6 +88,13 @@ trait SavedSearchInspectorTrait {
         ->setType($this->_displayType ?? 'table')
         ->execute()->first();
     }
+    if (is_array($this->display)) {
+      // Ensure array keys are always defined even for unsaved "preview" mode
+      $this->display += [
+        'id' => NULL,
+        'name' => NULL,
+      ];
+    }
   }
 
   /**