Move financialacl code from buildMembershipTypeValues to hook
authoreileen <emcnaughton@wikimedia.org>
Fri, 23 Oct 2020 04:52:53 +0000 (17:52 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 23 Oct 2020 04:52:53 +0000 (17:52 +1300)
CRM/Member/BAO/Membership.php
CRM/Member/BAO/MembershipType.php
ext/financialacls/financialacls.php

index 6e8a3099582544f7416fa2b7c33e63960b3bd00e..970190f19665db096030c20bc00cc201587dae1f 100644 (file)
@@ -1512,7 +1512,10 @@ WHERE  civicrm_membership.contact_id = civicrm_contact.id
   }
 
   /**
-   * Build an array of available membership types.
+   * Build an array of available membership types in the current context.
+   *
+   * While core does not do anything context specific extensions may filter
+   * or alter amounts based on user details.
    *
    * @param CRM_Core_Form $form
    * @param array $membershipTypeID
@@ -1527,7 +1530,7 @@ WHERE  civicrm_membership.contact_id = civicrm_contact.id
    */
   public static function buildMembershipTypeValues($form, $membershipTypeID = [], $activeOnly = FALSE) {
     $membershipTypeIDS = (array) $membershipTypeID;
-    $membershipTypeValues = CRM_Member_BAO_MembershipType::getPermissionedMembershipTypes();
+    $membershipTypeValues = CRM_Member_BAO_MembershipType::getAllMembershipTypes();
 
     // MembershipTypes are already filtered by domain, filter as appropriate by is_active & a passed in list of ids.
     foreach ($membershipTypeValues as $id => $type) {
index 581f11d686a177c33dbe59af36cdb75e73f82433..6ddf5172e66d88e7d2f06273e7c73796c21d86bd 100644 (file)
@@ -860,21 +860,4 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType {
     return self::getAllMembershipTypes()[$id];
   }
 
-  /**
-   * Get an array of all membership types the contact is permitted to access.
-   *
-   * @throws \CiviCRM_API3_Exception
-   */
-  public static function getPermissionedMembershipTypes() {
-    $types = self::getAllMembershipTypes();
-    $financialTypes = NULL;
-    $financialTypes = CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
-    foreach ($types as $id => $type) {
-      if (!isset($financialTypes[$type['financial_type_id']])) {
-        unset($types[$id]);
-      }
-    }
-    return $types;
-  }
-
 }
index 7c8e7e4eb46c56a0b315ec0f91572456bddaa8d4..0aa087dc79fbdb81d745be82c6aae7a49567d7f5 100644 (file)
@@ -214,6 +214,24 @@ function financialacls_civicrm_buildAmount($component, $form, &$feeBlock) {
   }
 }
 
+/**
+ * Remove unpermitted membership types from selection availability..
+ *
+ * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_membershipTypeValues
+ *
+ * @param \CRM_Core_Form $form
+ * @param array $membershipTypeValues
+ */
+function financialacls_civicrm_membershipTypeValues($form, &$membershipTypeValues) {
+  $financialTypes = NULL;
+  $financialTypes = CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
+  foreach ($membershipTypeValues as $id => $type) {
+    if (!isset($financialTypes[$type['financial_type_id']])) {
+      unset($membershipTypeValues[$id]);
+    }
+  }
+}
+
 // --- Functions below this ship commented out. Uncomment as required. ---
 
 /**