Skip to content

Commit

Permalink
Merge pull request #15940 from seamuslee001/dev_financial_105
Browse files Browse the repository at this point in the history
dev/financial#105 Add CSS class onto the radio button payment processor options
  • Loading branch information
mattwire authored Feb 19, 2020
2 parents d36fcd1 + 15a05fc commit ce8dad0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
12 changes: 10 additions & 2 deletions CRM/Contribute/Form/Contribution/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,18 @@ public function buildQuickForm() {
$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, " "
NULL, " ", FALSE, $optAttributes
);
}
elseif (!empty($pps)) {
Expand Down
16 changes: 14 additions & 2 deletions CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1147,17 +1147,29 @@ public function get_template_vars($name = NULL) {
* @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);

Expand Down
11 changes: 10 additions & 1 deletion CRM/Event/Form/Registration/Register.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,18 @@ public function buildQuickForm() {
}

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, " "
NULL, " ", FALSE, $optAttributes
);
}
elseif (!empty($pps)) {
Expand Down

0 comments on commit ce8dad0

Please sign in to comment.