SavedSearch - Add pseudoconstant for api_entity field
authorColeman Watts <coleman@civicrm.org>
Sun, 29 Aug 2021 23:58:17 +0000 (19:58 -0400)
committerColeman Watts <coleman@civicrm.org>
Sun, 29 Aug 2021 23:58:17 +0000 (19:58 -0400)
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
CRM/Contact/DAO/SavedSearch.php
xml/schema/Contact/SavedSearch.xml

index 3d3c4f2785abb68b56515f3d484d83bbeb32bce8..f430ccc84f38bdcd3c9905357055ae97477e059b 100644 (file)
@@ -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');
+  }
+
 }
index c0ecd2a212d3c9626139c8ef968a7f7feb6feed1..84f3e161e6e8921e96c4acf70bae3f004b2a3376 100644 (file)
@@ -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' => [
index 1be44e62ff9c1624a90272367b7a42fa6401c558..d0146e6709e86ac979af167b6292b6b80299534a 100644 (file)
     <length>255</length>
     <comment>Entity name for API based search</comment>
     <add>5.24</add>
+    <pseudoconstant>
+      <callback>CRM_Contact_BAO_SavedSearch::getApiEntityOptions</callback>
+    </pseudoconstant>
   </field>
 
   <field>