From a5399a39d784cdf51d6e62cec7487f67dd2d6f44 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 12 Feb 2015 11:20:33 +1300 Subject: [PATCH] CRM-15955 move credit card block to close to the top of the back office contribution form --- CRM/Contribute/Form/Contribution.php | 98 ++++++++++++------- .../CRM/Contribute/Form/Contribution.tpl | 15 +++ 2 files changed, 76 insertions(+), 37 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 53d6750d88..35ca917350 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -573,53 +573,21 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $paneNames[ts('Premium Information')] = 'Premium'; } + $billingPanes = array(); if ($this->_mode) { if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE) == TRUE) { $buildRecurBlock = TRUE; foreach ($this->billingPane as $name => $label) { if (!empty($this->billingFieldSets[$name]['fields'])) { - //@todo reduce variation so we don't have to convert 'credit_card' to 'CreditCard' - $paneNames[$label] = CRM_Utils_String::convertStringToCamel($name); + // @todo reduce variation so we don't have to convert 'credit_card' to 'CreditCard' + $billingPanes[$label] = $this->generatePane(CRM_Utils_String::convertStringToCamel($name), $defaults); } } } } foreach ($paneNames as $name => $type) { - $urlParams = "snippet=4&formType={$type}"; - if ($this->_mode) { - $urlParams .= "&mode={$this->_mode}"; - } - - $open = 'false'; - if ($type == 'CreditCard' || - $type == 'DirectDebit' - ) { - $open = 'true'; - } - - $allPanes[$name] = array( - 'url' => CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams), - 'open' => $open, - 'id' => $type, - ); - - // see if we need to include this paneName in the current form - if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) || - CRM_Utils_Array::value("hidden_{$type}", $defaults) - ) { - $showAdditionalInfo = TRUE; - $allPanes[$name]['open'] = 'true'; - } - - if ($type == 'CreditCard' || $type == 'DirectDebit') { - //@todo would be good to align tpl name with form name... - $this->add('hidden', 'hidden_' . $type, 1); - } - else { - $additionalInfoFormFunction = 'build' . $type; - CRM_Contribute_Form_AdditionalInfo::$additionalInfoFormFunction($this); - } + $allPanes[$name] = $this->generatePane($type, $defaults); } if (empty($this->_recurPaymentProcessors)) { $buildRecurBlock = FALSE; @@ -631,8 +599,8 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $this->assign('buildRecurBlock', $buildRecurBlock); $qfKey = $this->controller->_key; $this->assign('qfKey', $qfKey); + $this->assign('billingPanes', $billingPanes); $this->assign('allPanes', $allPanes); - $this->assign('showAdditionalInfo', $showAdditionalInfo); if ($this->_formType) { $this->assign('formType', $this->_formType); @@ -1833,4 +1801,60 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } } + /** + * Generate the data to construct a snippet based pane. + * + * This form also assigns the showAdditionalInfo var based on historical code. + * This appears to mean 'there is a pane to show'. + * + * @param string $type + * Type of Pane - this is generally used to determine the function name used to build it + * - e.g CreditCard, AdditionalDetail + * @param array $defaults + * + * @return array + * We aim to further refactor & simplify this but currently + * - the panes array + * - should additional info be shown? + */ + protected function generatePane($type, $defaults) { + $urlParams = "snippet=4&formType={$type}"; + if ($this->_mode) { + $urlParams .= "&mode={$this->_mode}"; + } + + $open = 'false'; + if ($type == 'CreditCard' || + $type == 'DirectDebit' + ) { + $open = 'true'; + } + + $pane = array( + 'url' => CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams), + 'open' => $open, + 'id' => $type, + ); + + // See if we need to include this paneName in the current form. + if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) || + CRM_Utils_Array::value("hidden_{$type}", $defaults) + ) { + $this->assign('showAdditionalInfo', TRUE); + $pane['open'] = 'true'; + } + + if ($type == 'CreditCard' || $type == 'DirectDebit') { + // @todo would be good to align tpl name with form name... + // @todo document why this hidden variable is required. + $this->add('hidden', 'hidden_' . $type, 1); + return $pane; + } + else { + $additionalInfoFormFunction = 'build' . $type; + CRM_Contribute_Form_AdditionalInfo::$additionalInfoFormFunction($this); + return $pane; + } + } + } diff --git a/templates/CRM/Contribute/Form/Contribution.tpl b/templates/CRM/Contribute/Form/Contribution.tpl index 721a156e00..f42e0d9741 100644 --- a/templates/CRM/Contribute/Form/Contribution.tpl +++ b/templates/CRM/Contribute/Form/Contribution.tpl @@ -218,6 +218,21 @@ {/if} + +
+ {* Billing Pane is the only billing pane currently *} + {foreach from=$billingPanes key=paneName item=paneValue} +
+
+ {$paneName} +
+
+
+
+
+ {/foreach} +
+
-- 2.25.1