Allow descriptions for payment fields (add via paymentFieldsMetaData 'description'
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Thu, 23 Aug 2018 10:12:34 +0000 (11:12 +0100)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Mon, 3 Sep 2018 21:24:12 +0000 (22:24 +0100)
CRM/Core/Payment.php
CRM/Core/Payment/Form.php
templates/CRM/Core/BillingBlock.tpl

index 13f506bcd118e2627c14e1fe5cb51e63362b139b..25de4a781f4ef1fe1ce52ad47ac079ac41eb7361 100644 (file)
@@ -689,6 +689,7 @@ abstract class CRM_Core_Payment {
           'class' => 'creditcard',
         ),
         'is_required' => TRUE,
+        // 'description' => '16 digit card number', // If you enable a description field it will be shown below the field on the form
       ),
       'cvv2' => array(
         'htmlType' => 'text',
index 60e946d7dd0283edbad023982c0f62215ec8427c..1200aef0e31e2fb48d9dfc0477bea4f7b7a72505 100644 (file)
@@ -113,7 +113,7 @@ class CRM_Core_Payment_Form {
    *   Fields that are to be shown on the payment form.
    */
   protected static function addCommonFields(&$form, $paymentFields) {
-    $requiredPaymentFields = array();
+    $requiredPaymentFields = $paymentFieldsMetadata = [];
     foreach ($paymentFields as $name => $field) {
       if ($field['htmlType'] == 'chainSelect') {
         $form->addChainSelect($field['name'], array('required' => FALSE));
@@ -129,8 +129,10 @@ class CRM_Core_Payment_Form {
       // This will cause the fields to be marked as required - but it is up to the payment processor to
       // validate it.
       $requiredPaymentFields[$field['name']] = $field['is_required'];
+      $paymentFieldsMetadata[$field['name']] = $field;
     }
 
+    $form->assign('paymentFieldsMetadata', $paymentFieldsMetadata);
     $form->assign('requiredPaymentFields', $requiredPaymentFields);
   }
 
index 73050a5e3737112ebe54716f6cf72fe820abe03b..3e15fce070d95c72f9456e777c72938bd7436c2a 100644 (file)
@@ -41,7 +41,9 @@
             </div>
             <div class="content">
                 {$form.$paymentField.html}
-              {if $paymentField == 'cvv2'}{* @todo move to form assignment*}
+              {if $paymentFieldsMetadata.$name.description}
+                <div class="description">{$paymentFieldsMetadata.$name.description}</div>
+              {elseif $paymentField == 'cvv2'}{* @todo move to form assignment*}
                 <span class="cvv2-icon" title="{ts}Usually the last 3-4 digits in the signature area on the back of the card.{/ts}"> </span>
               {/if}
               {if $paymentField == 'credit_card_type'}