diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php index 3e6450edde21..ea4ebafd2ae3 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php @@ -94,19 +94,8 @@ public function _run(\Civi\Api4\Generic\Result $result) { throw new UnauthorizedException('Access denied'); } $this->loadSavedSearch(); - if (is_string($this->display)) { - $this->display = SearchDisplay::get(FALSE) - ->setSelect(['*', 'type:name']) - ->addWhere('name', '=', $this->display) - ->addWhere('saved_search_id', '=', $this->savedSearch['id']) - ->execute()->single(); - } - elseif (is_null($this->display)) { - $this->display = SearchDisplay::getDefault(FALSE) - ->addSelect('*', 'type:name') - ->setSavedSearch($this->savedSearch) - ->execute()->first(); - } + $this->loadSearchDisplay(); + // Displays with acl_bypass must be embedded on an afform which the user has access to if ( $this->checkPermissions && !empty($this->display['acl_bypass']) && @@ -1029,4 +1018,25 @@ private function addFilterLabel($fieldName, $value) { } } + /** + * Loads display if not already an array + */ + private function loadSearchDisplay(): void { + // Display name given + if (is_string($this->display)) { + $this->display = SearchDisplay::get(FALSE) + ->setSelect(['*', 'type:name']) + ->addWhere('name', '=', $this->display) + ->addWhere('saved_search_id', '=', $this->savedSearch['id']) + ->execute()->single(); + } + // Null given - use default display + elseif (is_null($this->display)) { + $this->display = SearchDisplay::getDefault(FALSE) + ->addSelect('*', 'type:name') + ->setSavedSearch($this->savedSearch) + ->execute()->first(); + } + } + }