Skip to content

Commit

Permalink
Merge pull request #25433 from eileenmcnaughton/sk_admin
Browse files Browse the repository at this point in the history
Do not crash the whole SearchKit UI if one entity fails
  • Loading branch information
colemanw authored Jan 31, 2023
2 parents bfdb784 + 4d8aca0 commit be45150
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions ext/search_kit/Civi/Search/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Civi\Search;

use Civi\Api4\Action\SearchDisplay\AbstractRunAction;
use Civi\Api4\Entity;
use Civi\Api4\Extension;
use Civi\Api4\Query\SqlEquation;
use Civi\Api4\Query\SqlFunction;
Expand All @@ -30,6 +31,7 @@ class Admin {
* Returns clientside data needed for the `crmSearchAdmin` Angular module.
*
* @return array
* @throws \CRM_Core_Exception
*/
public static function getAdminSettings():array {
$schema = self::getSchema();
Expand Down Expand Up @@ -119,10 +121,11 @@ public static function getStyles():array {
* Fetch all entities the current user has permission to `get`.
*
* @return array[]
* @throws \CRM_Core_Exception
*/
public static function getSchema(): array {
$schema = [];
$entities = \Civi\Api4\Entity::get()
$entities = Entity::get()
->addSelect('name', 'title', 'title_plural', 'bridge_title', 'type', 'primary_key', 'description', 'label_field', 'icon', 'dao', 'bridge', 'ui_join_filters', 'searchable', 'order_by')
->addWhere('searchable', '!=', 'none')
->addOrderBy('title_plural')
Expand All @@ -141,11 +144,17 @@ public static function getSchema(): array {
if (!empty($paths['add'])) {
$entity['addPath'] = $paths['add'];
}
$getFields = civicrm_api4($entity['name'], 'getFields', [
'select' => ['name', 'title', 'label', 'description', 'type', 'options', 'input_type', 'input_attrs', 'data_type', 'serialize', 'entity', 'fk_entity', 'readonly', 'operators', 'suffixes', 'nullable'],
'where' => [['deprecated', '=', FALSE], ['name', 'NOT IN', ['api_key', 'hash']]],
'orderBy' => ['label'],
]);
try {
$getFields = civicrm_api4($entity['name'], 'getFields', [
'select' => ['name', 'title', 'label', 'description', 'type', 'options', 'input_type', 'input_attrs', 'data_type', 'serialize', 'entity', 'fk_entity', 'readonly', 'operators', 'suffixes', 'nullable'],
'where' => [['deprecated', '=', FALSE], ['name', 'NOT IN', ['api_key', 'hash']]],
'orderBy' => ['label'],
]);
}
catch (\CRM_Core_Exception $e) {
\Civi::log()->warning('Entity could not be loaded', ['entity' => $entity['name']]);
continue;
}
foreach ($getFields as $field) {
$field['fieldName'] = $field['name'];
// Hack for RelationshipCache to make Relationship fields editable
Expand Down Expand Up @@ -408,7 +417,11 @@ private static function getJoinConditions(string $nearCol, string $farCol, strin
*
* @param string $alias
* @param array ...$entities
*
* @return array
*
* @throws \CRM_Core_Exception
* @throws \Civi\API\Exception\NotImplementedException
*/
private static function getJoinDefaults(string $alias, ...$entities):array {
$conditions = [];
Expand Down

0 comments on commit be45150

Please sign in to comment.