From 5bf36e283b4e23ae6090eaf660e0f11b72751b13 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 9 Dec 2022 14:30:38 -0500 Subject: [PATCH] SearchKit - Ensure id & name are defined when loading saved searches --- .../Generic/Traits/SavedSearchInspectorTrait.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Civi/Api4/Generic/Traits/SavedSearchInspectorTrait.php b/Civi/Api4/Generic/Traits/SavedSearchInspectorTrait.php index f40b384690..1e2b87ce66 100644 --- a/Civi/Api4/Generic/Traits/SavedSearchInspectorTrait.php +++ b/Civi/Api4/Generic/Traits/SavedSearchInspectorTrait.php @@ -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, + ]; + } } /** -- 2.25.1