From 6cef116e78286b5d34ececd7f2261504b0fc476a Mon Sep 17 00:00:00 2001 From: colemanw Date: Mon, 3 Jul 2023 15:22:09 -0400 Subject: [PATCH] SearchKit - Provide context information to subscribers --- .../Generic/Traits/SavedSearchInspectorTrait.php | 5 +++++ .../Civi/Api4/Action/SearchDisplay/GetDefault.php | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Civi/Api4/Generic/Traits/SavedSearchInspectorTrait.php b/Civi/Api4/Generic/Traits/SavedSearchInspectorTrait.php index ce6cbb325b..fbef3dffb9 100644 --- a/Civi/Api4/Generic/Traits/SavedSearchInspectorTrait.php +++ b/Civi/Api4/Generic/Traits/SavedSearchInspectorTrait.php @@ -87,6 +87,11 @@ trait SavedSearchInspectorTrait { $this->display = \Civi\Api4\SearchDisplay::getDefault(FALSE) ->addSelect('*', 'type:name') ->setSavedSearch($this->savedSearch) + ->setContext([ + 'filters' => $this->filters ?? NULL, + 'formName' => $this->formName ?? NULL, + 'fieldName' => $this->fieldName ?? NULL, + ]) // Set by AutocompleteAction ->setType($this->_displayType ?? 'table') ->execute()->first(); diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetDefault.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetDefault.php index 4e618dc056..994e2018ec 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetDefault.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetDefault.php @@ -16,10 +16,14 @@ use Civi\Api4\Query\SqlFunctionGROUP_CONCAT; use Civi\Api4\Utils\CoreUtil; /** - * Return the default results table for a saved search. + * Generate the default display for a saved search. + * + * Dispatches `civi.search.defaultDisplay` event to allow subscribers to provide a display based on context. * * @method $this setType(string $type) * @method string getType() + * @method $this setContext(array $context) + * @method array getContext() * @package Civi\Api4\Action\SearchDisplay */ class GetDefault extends \Civi\Api4\Generic\AbstractAction { @@ -40,6 +44,12 @@ class GetDefault extends \Civi\Api4\Generic\AbstractAction { */ protected $type = 'table'; + /** + * Provide context information; passed through to `civi.search.defaultDisplay` subscribers + * @var array + */ + protected $context = []; + /** * @var array */ @@ -60,6 +70,7 @@ class GetDefault extends \Civi\Api4\Generic\AbstractAction { if (!strlen($label) && !empty($this->savedSearch['api_entity'])) { $label = CoreUtil::getInfoItem($this->savedSearch['api_entity'], 'title_plural'); } + // Initialize empty display $display = [ 'id' => NULL, 'name' => NULL, @@ -76,6 +87,7 @@ class GetDefault extends \Civi\Api4\Generic\AbstractAction { 'savedSearch' => $this->savedSearch, 'display' => &$display, 'apiAction' => $this, + 'context' => $this->context, ])); $fields = $this->entityFields(); -- 2.25.1