Merge pull request #24047 from kurund/export-fixes
[civicrm-core.git] / CRM / Member / Page / Tab.php
index 3d418592fc987e26f47b30c791aa397e9eacc3f5..085212a2e8aced22cd203b54f91aa90c4f141946 100644 (file)
@@ -27,6 +27,16 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
   public $_permission = NULL;
   public $_contactId = NULL;
 
+  /**
+   * @var bool
+   */
+  private $_isPaymentProcessor = FALSE;
+
+  /**
+   * @var bool
+   */
+  private $_accessContribution = FALSE;
+
   /**
    * called when action is browse.
    */
@@ -118,8 +128,8 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
         $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported(
           $membership[$dao->id]['membership_id']);
         $links = self::links('all',
-            NULL,
-            NULL,
+            FALSE,
+            FALSE,
             $isCancelSupported,
             $isUpdateBilling
         );
@@ -240,7 +250,7 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
   /**
    * called when action is view.
    *
-   * @return null
+   * @return mixed
    */
   public function view() {
     $controller = new CRM_Core_Controller_Simple(
@@ -258,9 +268,20 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
   /**
    * called when action is update or new.
    *
-   * @return null
+   * @return mixed
    */
   public function edit() {
+    // We're trying to edit existing memberships or create a new one so we'll first check that a membership
+    // type is configured and active, if we don't do this we instead show a permissions error and status bounce.
+    $membershipTypes = \Civi\Api4\MembershipType::get(TRUE)
+      ->addWhere('is_active', '=', TRUE)
+      // we only need one, more is great but a single result lets us proceed!
+      ->setLimit(1)
+      ->execute();
+    if (empty($membershipTypes)) {
+      CRM_Core_Error::statusBounce(ts('You do not appear to have any active membership types configured, please add an active membership type and try again.'));
+    }
+
     // set https for offline cc transaction
     $mode = CRM_Utils_Request::retrieve('mode', 'Alphanumeric', $this);
     if ($mode == 'test' || $mode == 'live') {
@@ -475,8 +496,8 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
    * Get action links.
    *
    * @param string $status
-   * @param null $isPaymentProcessor
-   * @param null $accessContribution
+   * @param bool $isPaymentProcessor
+   * @param bool $accessContribution
    * @param bool $isCancelSupported
    * @param bool $isUpdateBilling
    *
@@ -485,8 +506,8 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
    */
   public static function &links(
     $status = 'all',
-    $isPaymentProcessor = NULL,
-    $accessContribution = NULL,
+    $isPaymentProcessor = FALSE,
+    $accessContribution = FALSE,
     $isCancelSupported = FALSE,
     $isUpdateBilling = FALSE
   ) {