From e3d278330cfb04655a9572e6aaa004e7d9fc5d0b Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 25 Dec 2021 18:38:45 -0500 Subject: [PATCH] Afform - Add field types + pseudoconstant metadata to AfformSubmission entity The html type info is needed for the fields to be usable in the Afform GUI. The reason for adding the pseudoconstant is to facilitate automatically fetching the title from the afAdminFormSubmissionList form. This could be inefficient for sites with thousands of forms, but I think that's sufficiently mitigated by the fact that this pseudoconstant won'be be used for much; it won't generally be loaded onto the client-side. --- .../core/CRM/Afform/BAO/AfformSubmission.php | 13 +++++++++++++ .../core/CRM/Afform/DAO/AfformSubmission.php | 14 +++++++++++++- .../xml/schema/CRM/Afform/AfformSubmission.xml | 12 ++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ext/afform/core/CRM/Afform/BAO/AfformSubmission.php b/ext/afform/core/CRM/Afform/BAO/AfformSubmission.php index 5e2bc34bb7..6985388f71 100644 --- a/ext/afform/core/CRM/Afform/BAO/AfformSubmission.php +++ b/ext/afform/core/CRM/Afform/BAO/AfformSubmission.php @@ -3,4 +3,17 @@ use CRM_Afform_ExtensionUtil as E; class CRM_Afform_BAO_AfformSubmission extends CRM_Afform_DAO_AfformSubmission { + /** + * Pseudoconstant callback for `afform_name` + * @return array + */ + public static function getAllAfformsByName() { + return \Civi\Api4\Afform::get(FALSE) + ->addSelect('name', 'title') + ->addOrderBy('title') + ->execute() + ->indexBy('name') + ->column('title'); + } + } diff --git a/ext/afform/core/CRM/Afform/DAO/AfformSubmission.php b/ext/afform/core/CRM/Afform/DAO/AfformSubmission.php index c0a9f1c2ef..5ab88359cd 100644 --- a/ext/afform/core/CRM/Afform/DAO/AfformSubmission.php +++ b/ext/afform/core/CRM/Afform/DAO/AfformSubmission.php @@ -6,7 +6,7 @@ * * Generated from org.civicrm.afform/xml/schema/CRM/Afform/AfformSubmission.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:3018ef7f1283f7a38cdf9edae76df274) + * (GenCodeChecksum:6bffbfbde72fe38c0ab2bb8f49c945b8) */ use CRM_Afform_ExtensionUtil as E; @@ -129,6 +129,9 @@ class CRM_Afform_DAO_AfformSubmission extends CRM_Core_DAO { 'bao' => 'CRM_Afform_DAO_AfformSubmission', 'localizable' => 0, 'FKClassName' => 'CRM_Contact_DAO_Contact', + 'html' => [ + 'type' => 'EntityRef', + ], 'add' => '5.41', ], 'afform_name' => [ @@ -143,6 +146,12 @@ class CRM_Afform_DAO_AfformSubmission extends CRM_Core_DAO { 'entity' => 'AfformSubmission', 'bao' => 'CRM_Afform_DAO_AfformSubmission', 'localizable' => 0, + 'html' => [ + 'type' => 'Select', + ], + 'pseudoconstant' => [ + 'callback' => 'CRM_Afform_BAO_AfformSubmission::getAllAfformsByName', + ], 'add' => '5.41', ], 'data' => [ @@ -168,6 +177,9 @@ class CRM_Afform_DAO_AfformSubmission extends CRM_Core_DAO { 'entity' => 'AfformSubmission', 'bao' => 'CRM_Afform_DAO_AfformSubmission', 'localizable' => 0, + 'html' => [ + 'type' => 'Select Date', + ], 'readonly' => TRUE, 'add' => '5.41', ], diff --git a/ext/afform/core/xml/schema/CRM/Afform/AfformSubmission.xml b/ext/afform/core/xml/schema/CRM/Afform/AfformSubmission.xml index 28278d26ab..4d9b27ee0c 100644 --- a/ext/afform/core/xml/schema/CRM/Afform/AfformSubmission.xml +++ b/ext/afform/core/xml/schema/CRM/Afform/AfformSubmission.xml @@ -27,6 +27,9 @@ contact_id int unsigned User Contact ID + + EntityRef + 5.41 @@ -41,8 +44,14 @@ varchar 255 Afform Name + + Select + Name of submitted afform 5.41 + + CRM_Afform_BAO_AfformSubmission::getAllAfformsByName + @@ -57,6 +66,9 @@ submission_date timestamp + + Select Date + Submission Date/Time CURRENT_TIMESTAMP true -- 2.25.1