Move add/submit membership buttons to PHP level on membership tab
authorMatthew Wire <mjw@mjwconsult.co.uk>
Fri, 14 Aug 2020 15:33:28 +0000 (16:33 +0100)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Fri, 14 Aug 2020 15:35:14 +0000 (16:35 +0100)
CRM/Member/Page/Tab.php
templates/CRM/Member/Page/Tab.tpl

index ec2300d0ba5d783486b7fc675551eda146760f80..ef4d4551d510a37bb04daf749c4c116842aca7d2 100644 (file)
@@ -48,6 +48,23 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
     $permissions = [CRM_Core_Permission::VIEW];
     if (CRM_Core_Permission::check('edit memberships')) {
       $permissions[] = CRM_Core_Permission::EDIT;
+      $linkButtons['add_membership'] = [
+        'title' => ts('Add Membership'),
+        'url' => 'civicrm/contact/view/membership',
+        'qs' => "reset=1&action=add&cid={$this->_contactId}&context=membership",
+        'icon' => 'fa-plus-circle',
+        'accessKey' => 'N',
+      ];
+      if ($this->_accessContribution && CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()) {
+        $linkButtons['creditcard_membership'] = [
+          'title' => ts('Submit Credit Card Membership'),
+          'url' => 'civicrm/contact/view/membership',
+          'qs' => "reset=1&action=add&cid={$this->_contactId}&context=membership&mode=live",
+          'icon' => 'fa-credit-card',
+          'accessKey' => 'C',
+        ];
+      }
+      $this->assign('linkButtons', $linkButtons ?? []);
     }
     if (CRM_Core_Permission::check('delete in CiviMember')) {
       $permissions[] = CRM_Core_Permission::DELETE;
@@ -317,10 +334,7 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
     $this->preProcess();
 
     // check if we can process credit card membership
-    $newCredit = CRM_Core_Config::isEnabledBackOfficeCreditCardPayments();
-    $this->assign('newCredit', $newCredit);
-
-    if ($newCredit) {
+    if (CRM_Core_Config::isEnabledBackOfficeCreditCardPayments()) {
       $this->_isPaymentProcessor = TRUE;
     }
     else {
index 249634931c3a587f045942e00ffb46aa26723239..7e807c94822bc65ab7474c3a57fcb02cf3de55dc 100644 (file)
 {elseif $action eq 32768}  {* renew *}
     {include file="CRM/Member/Form/MembershipRenewal.tpl"}
 {elseif $action eq 16} {* Browse memberships for a contact *}
-    {if $permission EQ 'edit'}
-      {capture assign=newURL}{crmURL p="civicrm/contact/view/membership" q="reset=1&action=add&cid=`$contactId`&context=membership"}{/capture}{/if}
-
     {if $action ne 1 and $action ne 2 and $permission EQ 'edit'}
         <div class="help">
-            {if $permission EQ 'edit'}
-              {capture assign="link"}class="action-item" href="{$newURL}"{/capture}
-              {ts 1=$link}Click <a %1>Add Membership</a> to record a new membership.{/ts}
-              {if $newCredit}
-                {capture assign=newCreditURL}{crmURL p="civicrm/contact/view/membership" q="reset=1&action=add&cid=`$contactId`&context=membership&mode=live"}{/capture}
-                {capture assign="link"}class="action-item" href="{$newCreditURL}"{/capture}
-                {ts 1=$link}Click <a %1>Submit Credit Card Membership</a> to process a Membership on behalf of the member using their credit card.{/ts}
-                {/if}
+            {if $linkButtons.add_membership}
+              {ts}Click <em>Add Membership</em> to record a new membership.{/ts}
             {else}
-                {ts 1=$displayName}Current and inactive memberships for %1 are listed below.{/ts}
+              {ts 1=$displayName}Current and inactive memberships for %1 are listed below.{/ts}
+            {/if}
+            {if $linkButtons.creditcard_membership}
+              {ts}Click <em>Submit Credit Card Membership</em> to process a Membership on behalf of the member using their credit card.{/ts}
             {/if}
         </div>
 
         <div class="action-link">
-            <a accesskey="N" href="{$newURL}" class="button"><span><i class="crm-i fa-plus-circle" aria-hidden="true"></i> {ts}Add Membership{/ts}</span></a>
-            {if $accessContribution and $newCredit}
-                <a accesskey="N" href="{$newCreditURL}" class="button"><span><i class="crm-i fa-credit-card" aria-hidden="true"></i> {ts}Submit Credit Card Membership{/ts}</span></a><br /><br />
-            {else}
-                <br/ ><br/ >
-            {/if}
+          {include file="CRM/common/formButtons.tpl" location="top"}
         </div>
     {/if}
     {if NOT ($activeMembers or $inActiveMembers) and $action ne 2 and $action ne 1 and $action ne 8 and $action ne 4 and $action ne 32768}