}
foreach ($customOption as $opId => $opt) {
- $preHelpText = $postHelpText = '';
- $opt['label'] = !empty($opt['label']) ? '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' : '';
- if (!empty($opt['help_pre'])) {
- $preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span><span class="crm-price-amount-help-pre-separator">: </span>';
- }
- if (!empty($opt['help_post'])) {
- $postHelpText = '<span class="crm-price-amount-help-post-separator">: </span><span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
- }
-
- $taxAmount = $opt['tax_amount'] ?? NULL;
- if ($field->is_display_amounts) {
- $opt['label'] = !empty($opt['label']) ? $opt['label'] . '<span class="crm-price-amount-label-separator"> - </span>' : '';
- if (isset($taxAmount) && $invoicing) {
- $opt['label'] = $opt['label'] . self::getTaxLabel($opt, $valueFieldName);
- }
- else {
- $opt['label'] = $opt['label'] . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
- }
- }
-
- $opt['label'] = $preHelpText . $opt['label'] . $postHelpText;
- $count = CRM_Utils_Array::value('count', $opt, '');
- $max_value = CRM_Utils_Array::value('max_value', $opt, '');
- $priceVal = implode($separator, [$opt[$valueFieldName] + $taxAmount, $count, $max_value]);
+ $priceOptionText = self::buildPriceOptionText($opt, $field->is_display_amounts, $valueFieldName);
if (isset($opt['visibility_id'])) {
$visibility_id = $opt['visibility_id'];
}
$visibility_id = self::getVisibilityOptionID('public');
}
$extra = [
- 'price' => json_encode([$elementName, $priceVal]),
+ 'price' => json_encode([$elementName, $priceOptionText['priceVal']]),
'data-amount' => $opt[$valueFieldName],
'data-currency' => $currencyName,
'data-price-field-values' => json_encode($customOption),
$qf->assign('membershipFieldID', $field->id);
}
- $choice[$opt['id']] = $opt['label'];
+ $choice[$opt['id']] = $priceOptionText['label'];
$choiceAttrs[$opt['id']] = $extra;
if ($is_pay_later) {
$qf->add('text', 'txt-' . $elementName, $label, ['size' => '4']);
$none = ts('- none -');
}
- $choice['0'] = $none;
+ $choice['0'] = '<span class="crm-price-amount-label">' . $none . '</span>';
$choiceAttrs['0'] = ['price' => json_encode([$elementName, '0'])];
}
break;
case 'Select':
- $selectOption = $allowedOptions = $priceVal = [];
+ $selectOption = $allowedOptions = [];
foreach ($customOption as $opt) {
- $taxAmount = $opt['tax_amount'] ?? NULL;
- $count = CRM_Utils_Array::value('count', $opt, '');
- $max_value = CRM_Utils_Array::value('max_value', $opt, '');
-
- $preHelpText = $postHelpText = '';
- if (!empty($opt['help_pre'])) {
- $preHelpText = $opt['help_pre'] . ': ';
- }
- if (!empty($opt['help_post'])) {
- $postHelpText = ': ' . $opt['help_post'];
- }
-
- $taxAmount = $opt['tax_amount'] ?? NULL;
- if ($field->is_display_amounts) {
- $opt['label'] = !empty($opt['label']) ? $opt['label'] . ' - ' : '';
- if (isset($taxAmount) && $invoicing) {
- $opt['label'] = $opt['label'] . self::getTaxLabel($opt, $valueFieldName);
- }
- else {
- $opt['label'] = $opt['label'] . CRM_Utils_Money::format($opt[$valueFieldName]);
- }
- }
-
- $opt['label'] = $preHelpText . $opt['label'] . $postHelpText;
-
- $priceVal[$opt['id']] = implode($separator, [$opt[$valueFieldName] + $taxAmount, $count, $max_value]);
+ $priceOptionText = self::buildPriceOptionText($opt, $field->is_display_amounts, $valueFieldName);
+ $priceOptionText['label'] = strip_tags($priceOptionText['label']);
if (!in_array($opt['id'], $freezeOptions)) {
$allowedOptions[] = $opt['id'];
// CRM-14696 - Improve display for sold out price set options
else {
$opt['id'] = 'crm_disabled_opt-' . $opt['id'];
- $opt['label'] = $opt['label'] . ' (' . ts('Sold out') . ')';
+ $priceOptionText['label'] = $priceOptionText['label'] . ' (' . ts('Sold out') . ')';
}
- $selectOption[$opt['id']] = $opt['label'];
+ $selectOption[$opt['id']] = $priceOptionText['label'];
if ($is_pay_later) {
$qf->add('text', 'txt-' . $elementName, $label, ['size' => '4']);
$element = &$qf->add('select', $elementName, $label, $selectOption, $useRequired && $field->is_required, [
'placeholder' => ts('- select %1 -', [1 => $label]),
- 'price' => json_encode($priceVal),
+ 'price' => json_encode($priceOptionText['priceVal']),
'class' => 'crm-select2' . $class,
'data-price-field-values' => json_encode($customOption),
]);
break;
case 'CheckBox':
-
$check = [];
foreach ($customOption as $opId => $opt) {
- $taxAmount = $opt['tax_amount'] ?? NULL;
- $count = CRM_Utils_Array::value('count', $opt, '');
- $max_value = CRM_Utils_Array::value('max_value', $opt, '');
-
- $preHelpText = $postHelpText = '';
- $opt['label'] = !empty($opt['label']) ? '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' : '';
- if (!empty($opt['help_pre'])) {
- $preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span><span class="crm-price-amount-help-pre-separator">: </span>';
- }
- if (!empty($opt['help_post'])) {
- $postHelpText = '<span class="crm-price-amount-help-post-separator">: </span><span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
- }
-
- $taxAmount = $opt['tax_amount'] ?? NULL;
- if ($field->is_display_amounts) {
- $opt['label'] = !empty($opt['label']) ? $opt['label'] . '<span class="crm-price-amount-label-separator"> - </span>' : '';
- if (isset($taxAmount) && $invoicing) {
- $opt['label'] = $opt['label'] . self::getTaxLabel($opt, $valueFieldName);
- }
- else {
- $opt['label'] = $opt['label'] . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
- }
- }
-
- $opt['label'] = $preHelpText . $opt['label'] . $postHelpText;
-
- $priceVal = implode($separator, [$opt[$valueFieldName] + $taxAmount, $count, $max_value]);
- $check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $opt['label'],
+ $priceOptionText = self::buildPriceOptionText($opt, $field->is_display_amounts, $valueFieldName);
+ $check[$opId] = &$qf->createElement('checkbox', $opt['id'], NULL, $priceOptionText['label'],
[
- 'price' => json_encode([$opt['id'], $priceVal]),
+ 'price' => json_encode([$opt['id'], $priceOptionText['priceVal']]),
'data-amount' => $opt[$valueFieldName],
'data-currency' => $currencyName,
'visibility' => $opt['visibility_id'],
]
);
if ($is_pay_later) {
- $txtcheck[$opId] =& $qf->createElement('text', $opId, $opt['label'], ['size' => '4']);
+ $txtcheck[$opId] =& $qf->createElement('text', $opId, $priceOptionText['label'], ['size' => '4']);
$qf->addGroup($txtcheck, 'txt-' . $elementName, $label);
}
// CRM-6902 - Add "max" option for a price set field
}
}
+ /**
+ * Build the label and priceVal string for a price option.
+ *
+ * @param array $opt
+ * Price field option.
+ * @param bool $isDisplayAmounts
+ * @param string $valueFieldName
+ *
+ * @return array
+ * Price field option label, price value
+ */
+ public static function buildPriceOptionText($opt, $isDisplayAmounts, $valueFieldName) {
+ $preHelpText = $postHelpText = '';
+ $optionLabel = !empty($opt['label']) ? '<span class="crm-price-amount-label">' . $opt['label'] . '</span>' : '';
+ if (!empty($opt['help_pre'])) {
+ $preHelpText = '<span class="crm-price-amount-help-pre description">' . $opt['help_pre'] . '</span><span class="crm-price-amount-help-pre-separator">: </span>';
+ }
+ if (!empty($opt['help_post'])) {
+ $postHelpText = '<span class="crm-price-amount-help-post-separator">: </span><span class="crm-price-amount-help-post description">' . $opt['help_post'] . '</span>';
+ }
+
+ $invoicing = Civi::settings()->get('invoicing');
+ $taxAmount = $opt['tax_amount'] ?? NULL;
+ if ($isDisplayAmounts) {
+ $optionLabel = !empty($optionLabel) ? $optionLabel . '<span class="crm-price-amount-label-separator"> - </span>' : '';
+ if (isset($taxAmount) && $invoicing) {
+ $optionLabel = $optionLabel . self::getTaxLabel($opt, $valueFieldName);
+ }
+ else {
+ $optionLabel = $optionLabel . '<span class="crm-price-amount-amount">' . CRM_Utils_Money::format($opt[$valueFieldName]) . '</span>';
+ }
+ }
+
+ $optionLabel = $preHelpText . $optionLabel . $postHelpText;
+ $priceVal = implode('|', [$opt[$valueFieldName] + $taxAmount, $opt['count'] ?? '', $opt['max_value'] ?? '']);
+
+ return ['label' => $optionLabel, 'priceVal' => $priceVal];
+ }
+
/**
* Generate the label for price fields based on tax display setting option on CiviContribute Component Settings page.
*