From 09815e9cfa257852ee210ce7a045007d14638b79 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 30 Nov 2020 14:23:53 -0500 Subject: [PATCH] Add @searchable annotation to denote which API entities should be visible in Search Kit UI --- Civi/Api4/ACL.php | 1 + Civi/Api4/ActionSchedule.php | 1 + Civi/Api4/ContactType.php | 1 + Civi/Api4/CustomField.php | 2 +- Civi/Api4/CustomGroup.php | 2 +- Civi/Api4/Dashboard.php | 1 + Civi/Api4/DashboardContact.php | 1 + Civi/Api4/Domain.php | 2 +- Civi/Api4/Entity.php | 4 ++++ Civi/Api4/Generic/AbstractEntity.php | 3 ++- Civi/Api4/Generic/Traits/EntityBridge.php | 2 ++ Civi/Api4/Generic/Traits/OptionList.php | 3 +++ Civi/Api4/GroupNesting.php | 2 +- Civi/Api4/GroupOrganization.php | 1 + Civi/Api4/LocBlock.php | 5 ++++- Civi/Api4/MailSettings.php | 1 + Civi/Api4/Mapping.php | 1 + Civi/Api4/MappingField.php | 2 +- Civi/Api4/MessageTemplate.php | 2 +- Civi/Api4/Navigation.php | 1 + Civi/Api4/OptionGroup.php | 1 + Civi/Api4/PaymentProcessor.php | 1 + Civi/Api4/Relationship.php | 2 +- Civi/Api4/Route.php | 2 +- Civi/Api4/SavedSearch.php | 1 + Civi/Api4/Setting.php | 1 + Civi/Api4/StatusPreference.php | 1 + Civi/Api4/UFField.php | 1 + Civi/Api4/UFGroup.php | 1 + Civi/Api4/UFJoin.php | 1 + Civi/Api4/UFMatch.php | 1 + Civi/Api4/Utils/ReflectionUtils.php | 3 +++ ext/afform/core/Civi/Api4/Afform.php | 1 + ext/afform/core/Civi/Api4/AfformPalette.php | 1 + ext/afform/core/Civi/Api4/AfformTag.php | 1 + ext/search/Civi/Api4/SearchDisplay.php | 1 + ext/search/Civi/Search/Admin.php | 2 +- 37 files changed, 49 insertions(+), 11 deletions(-) diff --git a/Civi/Api4/ACL.php b/Civi/Api4/ACL.php index db5f774fde..01de7979ea 100644 --- a/Civi/Api4/ACL.php +++ b/Civi/Api4/ACL.php @@ -30,6 +30,7 @@ namespace Civi\Api4; * * Creating a new ACL requires at minimum an entity table, entity ID and object_table. * + * @searchable false * @see https://docs.civicrm.org/user/en/latest/initial-set-up/permissions-and-access-control * @package Civi\Api4 */ diff --git a/Civi/Api4/ActionSchedule.php b/Civi/Api4/ActionSchedule.php index 86cf74fc9d..2451af4292 100644 --- a/Civi/Api4/ActionSchedule.php +++ b/Civi/Api4/ActionSchedule.php @@ -28,6 +28,7 @@ namespace Civi\Api4; * * Creating a new ActionSchedule requires at minimum a title, mapping_id and entity_value. * + * @searchable false * @see https://docs.civicrm.org/user/en/latest/email/scheduled-reminders/ * @package Civi\Api4 */ diff --git a/Civi/Api4/ContactType.php b/Civi/Api4/ContactType.php index d2ebd1b25b..ac6731e569 100644 --- a/Civi/Api4/ContactType.php +++ b/Civi/Api4/ContactType.php @@ -33,5 +33,6 @@ namespace Civi\Api4; * @package Civi\Api4 */ class ContactType extends Generic\DAOEntity { + use Generic\Traits\OptionList; } diff --git a/Civi/Api4/CustomField.php b/Civi/Api4/CustomField.php index 7ac3b10657..1d4b7e104b 100644 --- a/Civi/Api4/CustomField.php +++ b/Civi/Api4/CustomField.php @@ -23,7 +23,7 @@ namespace Civi\Api4; * CustomField entity. * * @see https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/ - * + * @searchable false * @package Civi\Api4 */ class CustomField extends Generic\DAOEntity { diff --git a/Civi/Api4/CustomGroup.php b/Civi/Api4/CustomGroup.php index 14a878354b..7a87a2bde0 100644 --- a/Civi/Api4/CustomGroup.php +++ b/Civi/Api4/CustomGroup.php @@ -23,7 +23,7 @@ namespace Civi\Api4; * CustomGroup entity. * * @see https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/ - * + * @searchable false * @package Civi\Api4 */ class CustomGroup extends Generic\DAOEntity { diff --git a/Civi/Api4/Dashboard.php b/Civi/Api4/Dashboard.php index d5c9c12c77..24b42557a6 100644 --- a/Civi/Api4/Dashboard.php +++ b/Civi/Api4/Dashboard.php @@ -28,6 +28,7 @@ namespace Civi\Api4; * Displaying an item to a user is done with the `DashboardContact` entity. * * @see \Civi\Api4\DashboardContact + * @searchable false * @package Civi\Api4 */ class Dashboard extends Generic\DAOEntity { diff --git a/Civi/Api4/DashboardContact.php b/Civi/Api4/DashboardContact.php index 4ca8b6ecf6..f2538b326c 100644 --- a/Civi/Api4/DashboardContact.php +++ b/Civi/Api4/DashboardContact.php @@ -24,6 +24,7 @@ namespace Civi\Api4; * This places a dashboard item on a user's home screen. * * @see \Civi\Api4\Dashboard + * @searchable false * @package Civi\Api4 */ class DashboardContact extends Generic\DAOEntity { diff --git a/Civi/Api4/Domain.php b/Civi/Api4/Domain.php index a8a40cac74..8d356fac32 100644 --- a/Civi/Api4/Domain.php +++ b/Civi/Api4/Domain.php @@ -23,7 +23,7 @@ namespace Civi\Api4; * Domains - multisite instances of CiviCRM. * * @see https://docs.civicrm.org/sysadmin/en/latest/setup/multisite/ - * + * @searchable false * @package Civi\Api4 */ class Domain extends Generic\DAOEntity { diff --git a/Civi/Api4/Entity.php b/Civi/Api4/Entity.php index e326df3830..8dec4cebaf 100644 --- a/Civi/Api4/Entity.php +++ b/Civi/Api4/Entity.php @@ -84,6 +84,10 @@ class Entity extends Generic\AbstractEntity { 'name' => 'dao', 'description' => 'Class name for dao-based entities', ], + [ + 'name' => 'searchable', + 'description' => 'Should this entity be selectable in search kit UI', + ], [ 'name' => 'paths', 'data_type' => 'Array', diff --git a/Civi/Api4/Generic/AbstractEntity.php b/Civi/Api4/Generic/AbstractEntity.php index a07dc847d1..d4e775ecef 100644 --- a/Civi/Api4/Generic/AbstractEntity.php +++ b/Civi/Api4/Generic/AbstractEntity.php @@ -139,8 +139,9 @@ abstract class AbstractEntity { foreach (ReflectionUtils::getTraits(static::class) as $trait) { $info['type'][] = self::stripNamespace($trait); } + $info['searchable'] = !in_array('OptionList', $info['type']); $reflection = new \ReflectionClass(static::class); - $info += ReflectionUtils::getCodeDocs($reflection, NULL, ['entity' => $info['name']]); + $info = array_merge($info, ReflectionUtils::getCodeDocs($reflection, NULL, ['entity' => $info['name']])); unset($info['package'], $info['method']); return $info; } diff --git a/Civi/Api4/Generic/Traits/EntityBridge.php b/Civi/Api4/Generic/Traits/EntityBridge.php index 1123021dba..49b17680cd 100644 --- a/Civi/Api4/Generic/Traits/EntityBridge.php +++ b/Civi/Api4/Generic/Traits/EntityBridge.php @@ -15,6 +15,8 @@ namespace Civi\Api4\Generic\Traits; * A bridge is a small table that provides an intermediary link between two other tables. * * The API can automatically incorporate a Bridge into a join expression. + * + * Note: at time of writing this trait does nothing except affect the "type" shown in Entity::get() metadata. */ trait EntityBridge { diff --git a/Civi/Api4/Generic/Traits/OptionList.php b/Civi/Api4/Generic/Traits/OptionList.php index fb400cc55e..70936e0119 100644 --- a/Civi/Api4/Generic/Traits/OptionList.php +++ b/Civi/Api4/Generic/Traits/OptionList.php @@ -15,6 +15,9 @@ namespace Civi\Api4\Generic\Traits; * An optionList is a small entity whose primary purpose is to supply a semi-static list of options to fields in other entities. * * The options appear in the field metadata for other entities that reference this one via pseudoconstant. + * + * Note: At time of writing, this trait does nothing except toggle the searchable flag, (and adds "OptionList" to the "type" in Entity::get() metadata). + * @searchable false (FYI annotation isn't functional because this is a trait - workaround in AbstractEntity::getInfo) */ trait OptionList { diff --git a/Civi/Api4/GroupNesting.php b/Civi/Api4/GroupNesting.php index 10e6b8d174..a8376088b9 100644 --- a/Civi/Api4/GroupNesting.php +++ b/Civi/Api4/GroupNesting.php @@ -22,7 +22,7 @@ namespace Civi\Api4; * GroupNesting entity. * * @see \Civi\Api4\Group - * + * @searchable false * @package Civi\Api4 */ class GroupNesting extends Generic\DAOEntity { diff --git a/Civi/Api4/GroupOrganization.php b/Civi/Api4/GroupOrganization.php index d7229a22ff..87b683810b 100644 --- a/Civi/Api4/GroupOrganization.php +++ b/Civi/Api4/GroupOrganization.php @@ -27,5 +27,6 @@ namespace Civi\Api4; * @package Civi\Api4 */ class GroupOrganization extends Generic\DAOEntity { + use Generic\Traits\EntityBridge; } diff --git a/Civi/Api4/LocBlock.php b/Civi/Api4/LocBlock.php index 6b0ac77de9..03c2c9752c 100644 --- a/Civi/Api4/LocBlock.php +++ b/Civi/Api4/LocBlock.php @@ -13,8 +13,11 @@ namespace Civi\Api4; /** - * ContributionPage entity. + * LocBlock entity. * + * Links addresses, emails & phones to Events. + * + * @searchable false * @package Civi\Api4 */ class LocBlock extends Generic\DAOEntity { diff --git a/Civi/Api4/MailSettings.php b/Civi/Api4/MailSettings.php index 012a7869f2..d5c70622c6 100644 --- a/Civi/Api4/MailSettings.php +++ b/Civi/Api4/MailSettings.php @@ -22,6 +22,7 @@ namespace Civi\Api4; /** * MailSettings entity. * + * @searchable false * @package Civi\Api4 */ class MailSettings extends Generic\DAOEntity { diff --git a/Civi/Api4/Mapping.php b/Civi/Api4/Mapping.php index bd45b0b8d7..9c74f7d497 100644 --- a/Civi/Api4/Mapping.php +++ b/Civi/Api4/Mapping.php @@ -23,6 +23,7 @@ namespace Civi\Api4; * * This is a collection of MappingFields, for reuse in import, export, etc. * + * @searchable false * @package Civi\Api4 */ class Mapping extends Generic\DAOEntity { diff --git a/Civi/Api4/MappingField.php b/Civi/Api4/MappingField.php index 23cb5e0ca9..bde710c401 100644 --- a/Civi/Api4/MappingField.php +++ b/Civi/Api4/MappingField.php @@ -24,7 +24,7 @@ namespace Civi\Api4; * This represents one field in a Mapping collection. * * @see \Civi\Api4\Mapping - * + * @searchable false * @package Civi\Api4 */ class MappingField extends Generic\DAOEntity { diff --git a/Civi/Api4/MessageTemplate.php b/Civi/Api4/MessageTemplate.php index 10101db153..5f05a517d5 100644 --- a/Civi/Api4/MessageTemplate.php +++ b/Civi/Api4/MessageTemplate.php @@ -22,7 +22,7 @@ namespace Civi\Api4; * MsgTemplate entity. * * This is a collection of MsgTemplate, for reuse in import, export, etc. - * + * @searchable false * @package Civi\Api4 */ class MessageTemplate extends Generic\DAOEntity { diff --git a/Civi/Api4/Navigation.php b/Civi/Api4/Navigation.php index 3ae9e5cb09..57963db4e4 100644 --- a/Civi/Api4/Navigation.php +++ b/Civi/Api4/Navigation.php @@ -21,6 +21,7 @@ namespace Civi\Api4; /** * Navigation entity. * + * @searchable false * @package Civi\Api4 */ class Navigation extends Generic\DAOEntity { diff --git a/Civi/Api4/OptionGroup.php b/Civi/Api4/OptionGroup.php index 51a7c60a1d..a25bed1694 100644 --- a/Civi/Api4/OptionGroup.php +++ b/Civi/Api4/OptionGroup.php @@ -26,5 +26,6 @@ namespace Civi\Api4; * @package Civi\Api4 */ class OptionGroup extends Generic\DAOEntity { + use Generic\Traits\OptionList; } diff --git a/Civi/Api4/PaymentProcessor.php b/Civi/Api4/PaymentProcessor.php index c15a448733..c864069478 100644 --- a/Civi/Api4/PaymentProcessor.php +++ b/Civi/Api4/PaymentProcessor.php @@ -25,5 +25,6 @@ namespace Civi\Api4; * @package Civi\Api4 */ class PaymentProcessor extends Generic\DAOEntity { + use Generic\Traits\OptionList; } diff --git a/Civi/Api4/Relationship.php b/Civi/Api4/Relationship.php index dd76ecc23e..276da78074 100644 --- a/Civi/Api4/Relationship.php +++ b/Civi/Api4/Relationship.php @@ -23,7 +23,7 @@ namespace Civi\Api4; * Relationship entity. * * @see https://docs.civicrm.org/user/en/latest/organising-your-data/relationships/ - * + * @searchable false * @package Civi\Api4 */ class Relationship extends Generic\DAOEntity { diff --git a/Civi/Api4/Route.php b/Civi/Api4/Route.php index a407a5093e..6681b645ec 100644 --- a/Civi/Api4/Route.php +++ b/Civi/Api4/Route.php @@ -26,7 +26,7 @@ namespace Civi\Api4; * Note: this is a read-only api as routes are set via xml files and hooks. * * @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterMenu/ - * + * @searchable false * @package Civi\Api4 */ class Route extends \Civi\Api4\Generic\AbstractEntity { diff --git a/Civi/Api4/SavedSearch.php b/Civi/Api4/SavedSearch.php index 1262b6747e..79c5e0c2e9 100644 --- a/Civi/Api4/SavedSearch.php +++ b/Civi/Api4/SavedSearch.php @@ -25,6 +25,7 @@ namespace Civi\Api4; * Stores search parameters for populating smart groups with live results. * * @see https://docs.civicrm.org/user/en/latest/organising-your-data/smart-groups/ + * @searchable false * @package Civi\Api4 */ class SavedSearch extends Generic\DAOEntity { diff --git a/Civi/Api4/Setting.php b/Civi/Api4/Setting.php index a5d3654c98..f97627b6aa 100644 --- a/Civi/Api4/Setting.php +++ b/Civi/Api4/Setting.php @@ -25,6 +25,7 @@ namespace Civi\Api4; * Used to read/write persistent setting data from CiviCRM. * * @see \Civi\Core\SettingsBag + * @searchable false * @package Civi\Api4 */ class Setting extends Generic\AbstractEntity { diff --git a/Civi/Api4/StatusPreference.php b/Civi/Api4/StatusPreference.php index d56476e13e..4a2ece25dd 100644 --- a/Civi/Api4/StatusPreference.php +++ b/Civi/Api4/StatusPreference.php @@ -24,6 +24,7 @@ namespace Civi\Api4; * * For setting "hush" preferences for system check alerts. * + * @searchable false * @package Civi\Api4 */ class StatusPreference extends Generic\DAOEntity { diff --git a/Civi/Api4/UFField.php b/Civi/Api4/UFField.php index 2f8db8784c..6d044da207 100644 --- a/Civi/Api4/UFField.php +++ b/Civi/Api4/UFField.php @@ -23,6 +23,7 @@ namespace Civi\Api4; * UFField entity - aka profile fields. * * @see \Civi\Api4\UFGroup + * @searchable false * @package Civi\Api4 */ class UFField extends Generic\DAOEntity { diff --git a/Civi/Api4/UFGroup.php b/Civi/Api4/UFGroup.php index 2d66a72571..2f80638a07 100644 --- a/Civi/Api4/UFGroup.php +++ b/Civi/Api4/UFGroup.php @@ -23,6 +23,7 @@ namespace Civi\Api4; * UFGroup entity - AKA profiles. * * @see https://docs.civicrm.org/user/en/latest/organising-your-data/profiles/ + * @searchable false * @package Civi\Api4 */ class UFGroup extends Generic\DAOEntity { diff --git a/Civi/Api4/UFJoin.php b/Civi/Api4/UFJoin.php index a5c8ce9008..b1c874a93f 100644 --- a/Civi/Api4/UFJoin.php +++ b/Civi/Api4/UFJoin.php @@ -23,6 +23,7 @@ namespace Civi\Api4; * UFJoin entity - links profiles to the components/extensions they are used for. * * @see \Civi\Api4\UFGroup + * @searchable false * @package Civi\Api4 */ class UFJoin extends Generic\DAOEntity { diff --git a/Civi/Api4/UFMatch.php b/Civi/Api4/UFMatch.php index c7956c9d88..05cd8fa5a5 100644 --- a/Civi/Api4/UFMatch.php +++ b/Civi/Api4/UFMatch.php @@ -22,6 +22,7 @@ namespace Civi\Api4; /** * UFMatch entity - links civicrm contacts with users created externally * + * @searchable false * @package Civi\Api4 */ class UFMatch extends Generic\DAOEntity { diff --git a/Civi/Api4/Utils/ReflectionUtils.php b/Civi/Api4/Utils/ReflectionUtils.php index 0733b20f89..cb7ddb01dc 100644 --- a/Civi/Api4/Utils/ReflectionUtils.php +++ b/Civi/Api4/Utils/ReflectionUtils.php @@ -95,6 +95,9 @@ class ReflectionUtils { elseif ($key == 'throws' || $key == 'see') { $info[$key][] = implode(' ', $words); } + elseif ($key == 'searchable') { + $info[$key] = strtolower($words[0]) !== 'false'; + } elseif ($key == 'param' && $words) { $type = $words[0][0] !== '$' ? explode('|', array_shift($words)) : NULL; $param = rtrim(array_shift($words), '-:()/'); diff --git a/ext/afform/core/Civi/Api4/Afform.php b/ext/afform/core/Civi/Api4/Afform.php index 94abb0467b..8f1a400bd9 100644 --- a/ext/afform/core/Civi/Api4/Afform.php +++ b/ext/afform/core/Civi/Api4/Afform.php @@ -16,6 +16,7 @@ use Civi\Api4\Generic\BasicBatchAction; * The `prefill` and `submit` actions are used for preparing forms and processing submissions. * * @see https://lab.civicrm.org/extensions/afform + * @searchable false * @package Civi\Api4 */ class Afform extends Generic\AbstractEntity { diff --git a/ext/afform/core/Civi/Api4/AfformPalette.php b/ext/afform/core/Civi/Api4/AfformPalette.php index 981d5ad9a9..e803aa0176 100644 --- a/ext/afform/core/Civi/Api4/AfformPalette.php +++ b/ext/afform/core/Civi/Api4/AfformPalette.php @@ -4,6 +4,7 @@ namespace Civi\Api4; /** * Class AfformPalette + * @searchable false * @package Civi\Api4 */ class AfformPalette extends Generic\AbstractEntity { diff --git a/ext/afform/core/Civi/Api4/AfformTag.php b/ext/afform/core/Civi/Api4/AfformTag.php index e2b5b77e93..e2ca67f92b 100644 --- a/ext/afform/core/Civi/Api4/AfformTag.php +++ b/ext/afform/core/Civi/Api4/AfformTag.php @@ -3,6 +3,7 @@ namespace Civi\Api4; /** * Class AfformTag + * @searchable false * @package Civi\Api4 */ class AfformTag extends Generic\AbstractEntity { diff --git a/ext/search/Civi/Api4/SearchDisplay.php b/ext/search/Civi/Api4/SearchDisplay.php index 33f44977b2..93503b83d4 100644 --- a/ext/search/Civi/Api4/SearchDisplay.php +++ b/ext/search/Civi/Api4/SearchDisplay.php @@ -6,6 +6,7 @@ namespace Civi\Api4; * * Provided by the Search Kit extension. * + * @searchable false * @package Civi\Api4 */ class SearchDisplay extends Generic\DAOEntity { diff --git a/ext/search/Civi/Search/Admin.php b/ext/search/Civi/Search/Admin.php index ab90e7f02e..00448fee40 100644 --- a/ext/search/Civi/Search/Admin.php +++ b/ext/search/Civi/Search/Admin.php @@ -59,7 +59,7 @@ class Admin { $schema = []; $entities = \Civi\Api4\Entity::get() ->addSelect('name', 'title', 'type', 'title_plural', 'description', 'icon', 'paths') - ->addWhere('name', '!=', 'Entity') + ->addWhere('searchable', '=', TRUE) ->addOrderBy('title_plural') ->setChain([ 'get' => ['$name', 'getActions', ['where' => [['name', '=', 'get']]], ['params']], -- 2.25.1