Skip to content

Commit a0d5473

Browse files
committed
Add fallback to load CRM.vars.omnipay if not loaded via html-header region
1 parent 4c99e1b commit a0d5473

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

CRM/Core/Payment/OmnipayMultiProcessor.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,13 @@ public function buildForm(&$form) {
357357
$jsVariables[$clientSideKey] = $this->_paymentProcessor[$key];
358358
}
359359
}
360-
CRM_Core_Resources::singleton()->addVars('omnipay', $jsVariables);
360+
361+
\Civi::resources()->addVars('omnipay', $jsVariables);
362+
// Assign to smarty so we can add via tpl for drupal webform / default processor on contribution page because addVars doesn't work in that context
363+
// until https://github.com/civicrm/civicrm-core/pull/18141 is merged
364+
// Then we can set 'billing-block' above and remove the assign/tpl
365+
$form->assign('omnipayJSVars', $jsVariables);
366+
361367
if (is_array($regions)) {
362368
foreach ($regions as $region => $additions) {
363369
foreach ($additions as $addition) {

Metadata/omnipay_PaypalRest.mgd.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
//'billing-block-post' => [],
104104
'billing-block' => [
105105
['markup' => '<div id="paypal-button-container" class="crm-paypal-buttons"></div>', 'name' => 'paypal_button', 'weight' => 400],
106+
['template' => E::path('templates/CRM/Omnipaymultiprocessor/Form/OmnipayResource.tpl'), 'region' => 'billing-block', 'weight' => -1],
106107
['name' => 'paypal_script', 'weight' => 500, 'scriptUrl' => \Civi::resources()->addCacheCode(E::url('Metadata/js/omnipay_PaypalRest.js'))]
107108
],
108109
],
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{*
2+
+--------------------------------------------------------------------+
3+
| Copyright CiviCRM LLC. All rights reserved. |
4+
| |
5+
| This work is published under the GNU AGPLv3 license with some |
6+
| permitted exceptions and without any warranty. For full license |
7+
| and copyright information, see https://civicrm.org/licensing |
8+
+--------------------------------------------------------------------+
9+
*}
10+
{* Manually create the CRM.vars.omnipay here for cases where \Civi::resources()->addVars() does not work (eg. drupal webform_civicrm, contribution page paypal checkout is default *}
11+
{literal}
12+
<script type="text/javascript">
13+
CRM.$(function($) {
14+
$(document).ready(function() {
15+
if (typeof CRM.vars.omnipay === 'undefined') {
16+
var omnipay = {{/literal}{foreach from=$omnipayJSVars key=arrayKey item=arrayValue}{$arrayKey}:'{$arrayValue}',{/foreach}{literal}};
17+
CRM.vars.omnipay = omnipay;
18+
//console.log('added vars via tpl');
19+
}
20+
});
21+
});
22+
</script>
23+
{/literal}

0 commit comments

Comments
 (0)