Skip to content

Commit

Permalink
Afform - Add field types + pseudoconstant metadata to AfformSubmissio…
Browse files Browse the repository at this point in the history
…n 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.
  • Loading branch information
colemanw committed Dec 26, 2021
1 parent 4f5b062 commit e3d2783
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
13 changes: 13 additions & 0 deletions ext/afform/core/CRM/Afform/BAO/AfformSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@

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');
}

}
14 changes: 13 additions & 1 deletion ext/afform/core/CRM/Afform/DAO/AfformSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -129,6 +129,9 @@ public static function &fields() {
'bao' => 'CRM_Afform_DAO_AfformSubmission',
'localizable' => 0,
'FKClassName' => 'CRM_Contact_DAO_Contact',
'html' => [
'type' => 'EntityRef',
],
'add' => '5.41',
],
'afform_name' => [
Expand All @@ -143,6 +146,12 @@ public static function &fields() {
'entity' => 'AfformSubmission',
'bao' => 'CRM_Afform_DAO_AfformSubmission',
'localizable' => 0,
'html' => [
'type' => 'Select',
],
'pseudoconstant' => [
'callback' => 'CRM_Afform_BAO_AfformSubmission::getAllAfformsByName',
],
'add' => '5.41',
],
'data' => [
Expand All @@ -168,6 +177,9 @@ public static function &fields() {
'entity' => 'AfformSubmission',
'bao' => 'CRM_Afform_DAO_AfformSubmission',
'localizable' => 0,
'html' => [
'type' => 'Select Date',
],
'readonly' => TRUE,
'add' => '5.41',
],
Expand Down
12 changes: 12 additions & 0 deletions ext/afform/core/xml/schema/CRM/Afform/AfformSubmission.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<name>contact_id</name>
<type>int unsigned</type>
<title>User Contact ID</title>
<html>
<type>EntityRef</type>
</html>
<add>5.41</add>
</field>
<foreignKey>
Expand All @@ -41,8 +44,14 @@
<type>varchar</type>
<length>255</length>
<title>Afform Name</title>
<html>
<type>Select</type>
</html>
<comment>Name of submitted afform</comment>
<add>5.41</add>
<pseudoconstant>
<callback>CRM_Afform_BAO_AfformSubmission::getAllAfformsByName</callback>
</pseudoconstant>
</field>

<field>
Expand All @@ -57,6 +66,9 @@
<field>
<name>submission_date</name>
<type>timestamp</type>
<html>
<type>Select Date</type>
</html>
<title>Submission Date/Time</title>
<default>CURRENT_TIMESTAMP</default>
<readonly>true</readonly>
Expand Down

0 comments on commit e3d2783

Please sign in to comment.