From 341a0f0e320b27812e3b9789e89f9b1bc6fdfceb Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Wed, 7 Aug 2019 11:34:07 +0200 Subject: [PATCH] [#5] Add membership type configuration option in profile --- CRM/Twingle/Form/Profile.php | 30 ++++++++++++++++++++++++++ CRM/Twingle/Profile.php | 2 ++ templates/CRM/Twingle/Form/Profile.tpl | 5 +++++ 3 files changed, 37 insertions(+) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 29ed717..25f871c 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -224,6 +224,15 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { array('class' => 'crm-select2 huge') ); + $this->add( + 'select', // field type + 'membership_type_id', // field name + E::ts('Create membership of type'), // field label + array('' => E::ts('- none -')) + $this->getMembershipTypes(), // list of options + FALSE, // is not required + array('class' => 'crm-select2 huge') + ); + $this->add( 'text', // field type 'contribution_source', // field name @@ -349,6 +358,27 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { return $financial_types; } + /** + * Retrieves membership types present within the system as options for select + * form elements. + * + * @return array + * + * @throws \CiviCRM_API3_Exception + */ + public function getMembershipTypes() { + $membership_types = array(); + $query = civicrm_api3('MembershipType', 'get', array( + 'is_active' => 1, + 'option.limit' => 0, + 'return' => 'id,name' + )); + foreach ($query['values'] as $type) { + $membership_types[$type['id']] = $type['name']; + } + return $membership_types; + } + /** * Retrieves campaigns present within the system as options for select form * elements. diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index 85e6fd0..e818062 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -191,6 +191,7 @@ class CRM_Twingle_Profile { 'donation_receipt_groups', 'campaign', 'contribution_source', + 'membership_type_id', ); } @@ -250,6 +251,7 @@ class CRM_Twingle_Profile { 'donation_receipt_groups' => NULL, 'campaign' => NULL, 'contribution_source' => NULL, + 'membreship_type_id' => NULL, )); } diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index 773dfb7..c7ad9db 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -185,6 +185,11 @@ {$form.campaign.html} + + {$form.membership_type_id.label} + {$form.membership_type_id.html} + + {$form.contribution_source.label} {$form.contribution_source.html}