From ddc4b6b8710bf4214ccf9428067c5bfd52e95ff4 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 29 Aug 2021 19:58:17 -0400 Subject: [PATCH] SavedSearch - Add pseudoconstant for api_entity field This makes it easier to display in the UI what a search is for, e.g. `->addSelect('api_entity:label')` would return "Contacts" for a search of Contacts. --- CRM/Contact/BAO/SavedSearch.php | 13 +++++++++++++ CRM/Contact/DAO/SavedSearch.php | 5 ++++- xml/schema/Contact/SavedSearch.xml | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/SavedSearch.php b/CRM/Contact/BAO/SavedSearch.php index 3d3c4f2785..f430ccc84f 100644 --- a/CRM/Contact/BAO/SavedSearch.php +++ b/CRM/Contact/BAO/SavedSearch.php @@ -473,4 +473,17 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_ return CRM_Utils_System::url($path, ['reset' => 1, 'ssID' => $id]); } + /** + * Retrieve pseudoconstant options for $this->api_entity field + * @return array + */ + public static function getApiEntityOptions() { + return Civi\Api4\Entity::get(FALSE) + ->addSelect('name', 'title_plural') + ->addOrderBy('title_plural') + ->execute() + ->indexBy('name') + ->column('title_plural'); + } + } diff --git a/CRM/Contact/DAO/SavedSearch.php b/CRM/Contact/DAO/SavedSearch.php index c0ecd2a212..84f3e161e6 100644 --- a/CRM/Contact/DAO/SavedSearch.php +++ b/CRM/Contact/DAO/SavedSearch.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contact/SavedSearch.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:c884fe02dfd203d381429f83672e1a9e) + * (GenCodeChecksum:5e5799b7755c435363f2c8cdafd13055) */ /** @@ -277,6 +277,9 @@ class CRM_Contact_DAO_SavedSearch extends CRM_Core_DAO { 'entity' => 'SavedSearch', 'bao' => 'CRM_Contact_BAO_SavedSearch', 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_Contact_BAO_SavedSearch::getApiEntityOptions', + ], 'add' => '5.24', ], 'api_params' => [ diff --git a/xml/schema/Contact/SavedSearch.xml b/xml/schema/Contact/SavedSearch.xml index 1be44e62ff..d0146e6709 100644 --- a/xml/schema/Contact/SavedSearch.xml +++ b/xml/schema/Contact/SavedSearch.xml @@ -126,6 +126,9 @@ 255 Entity name for API based search 5.24 + + CRM_Contact_BAO_SavedSearch::getApiEntityOptions + -- 2.25.1