dev/financial#105 Add in additional class onto the radio button payment processor...
authorSeamus Lee <seamuslee001@gmail.com>
Sat, 23 Nov 2019 20:49:12 +0000 (07:49 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Sat, 23 Nov 2019 20:49:12 +0000 (07:49 +1100)
CRM/Contribute/Form/Contribution/Main.php
CRM/Core/Form.php
CRM/Event/Form/Registration/Register.php

index 2e102f83ee82c9f7103345c5cade43c8fe1343ab..376df66b382a6782ee1071eacbc69d48ee04b5bf 100644 (file)
@@ -320,10 +320,18 @@ class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_Contribu
       $this->add('text', 'total_amount', ts('Total Amount'), ['readonly' => TRUE], FALSE);
     }
     $pps = $this->getProcessors();
-
+    $optAttributes = [];
+    foreach ($pps as $ppKey => $ppval) {
+      if ($ppKey > 0) {
+        $optAttributes[$ppKey]['class'] = 'payment_processor_' . strtolower($this->_paymentProcessors[$ppKey]['payment_processor_type']);
+      }
+      else {
+        $optAttributes[$ppKey]['class'] = 'payment_processor_paylater';
+      }
+    }
     if (count($pps) > 1) {
       $this->addRadio('payment_processor_id', ts('Payment Method'), $pps,
-        NULL, "&nbsp;"
+        NULL, "&nbsp;", FALSE, $optAttributes
       );
     }
     elseif (!empty($pps)) {
index 5eb5167b312547b67ee642697452616bf82392e9..35df75d34fc95a5b83d22b9defb7917091548e44 100644 (file)
@@ -1150,17 +1150,29 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * @param array $attributes
    * @param null $separator
    * @param bool $required
+   * @param array $optionAttributes - Option specific attributes
    *
    * @return HTML_QuickForm_group
    */
-  public function &addRadio($name, $title, $values, $attributes = [], $separator = NULL, $required = FALSE) {
+  public function &addRadio($name, $title, $values, $attributes = [], $separator = NULL, $required = FALSE, $optionAttributes = []) {
     $options = [];
     $attributes = $attributes ? $attributes : [];
     $allowClear = !empty($attributes['allowClear']);
     unset($attributes['allowClear']);
     $attributes['id_suffix'] = $name;
     foreach ($values as $key => $var) {
-      $options[] = $this->createElement('radio', NULL, NULL, $var, $key, $attributes);
+      $optAttributes = $attributes;
+      if (!empty($optionAttributes[$key])) {
+        foreach ($optionAttributes[$key] as $optAttr => $optVal) {
+          if (!empty($optAttributes[$optAttr])) {
+            $optAttributes[$optAttr] .= ' ' . $optVal;
+          }
+          else {
+            $optAttributes[$optAttr] = $optVal;
+          }
+        }
+      }
+      $options[] = $this->createElement('radio', NULL, NULL, $var, $key, $optAttributes);
     }
     $group = $this->addGroup($options, $name, $title, $separator);
 
index 131e08eb2817631c90ad957af4351605f779ad47..1b5e56031cc387e649a5a8f64433c2a8602eec9d 100644 (file)
@@ -398,9 +398,18 @@ class CRM_Event_Form_Registration_Register extends CRM_Event_Form_Registration {
     }
 
     if ($this->_values['event']['is_monetary']) {
+      $optAttributes = [];
+      foreach ($pps as $ppKey => $ppval) {
+        if ($ppKey > 0) {
+          $optAttributes[$ppKey]['class'] = 'payment_processor_' . strtolower($this->_paymentProcessors[$ppKey]['payment_processor_type']);
+        }
+        else {
+          $optAttributes[$ppKey]['class'] = 'payment_processor_paylater';
+        }
+      }
       if (count($pps) > 1) {
         $this->addRadio('payment_processor_id', ts('Payment Method'), $pps,
-          NULL, "&nbsp;"
+          NULL, "&nbsp;", FALSE, $optAttributes
         );
       }
       elseif (!empty($pps)) {