Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mjwshared
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Extensions
mjwshared
Commits
166cbd03
Commit
166cbd03
authored
4 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Check if we've already loaded CRM.payment
parent
5c1b0216
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Mjwshared/Resources.php
+0
-100
0 additions, 100 deletions
CRM/Mjwshared/Resources.php
js/crm.payment.js
+3
-0
3 additions, 0 deletions
js/crm.payment.js
with
3 additions
and
100 deletions
CRM/Mjwshared/Resources.php
deleted
100644 → 0
+
0
−
100
View file @
5c1b0216
<?php
/**
* Class CRM_Mjwshared_Resources
*
* Currently (CiviCRM 5.24) \Civi::resources()->addVars() / CRM_Core_Resources::singleton()->addVars()
* only allows adding to ajax-snippet or html-header region. But we need to add to billing-block region
* @todo See https://github.com/civicrm/civicrm-core/pull/16888 for a core fix which will allow us to
* remove these compatibility functions
*/
class
CRM_Mjwshared_Resources
extends
CRM_Core_Resources
{
/**
* Added settings.
*
* Format is ($regionName => bool).
*
* @var array
*/
protected
$addedSettingsToRegion
=
[];
/**
* Add JavaScript variables to CRM.vars
*
* Example:
* From the server:
* CRM_Core_Resources::singleton()->addVars('myNamespace', array('foo' => 'bar'));
* Access var from javascript:
* CRM.vars.myNamespace.foo // "bar"
*
* @see http://wiki.civicrm.org/confluence/display/CRMDOC/Javascript+Reference
*
* @param string $nameSpace
* Usually the name of your extension.
* @param array $vars
* @param string $region
* The region to add settings to (eg. for payment processors usually billing-block)
*
* @return CRM_Core_Resources
*/
public
static
function
compatAddVars
(
$nameSpace
,
$vars
,
$region
=
NULL
)
{
$resourcesObject
=
CRM_Core_Resources
::
singleton
();
$existing
=
CRM_Utils_Array
::
value
(
$nameSpace
,
CRM_Utils_Array
::
value
(
'vars'
,
$resourcesObject
->
settings
),
[]);
$vars
=
$resourcesObject
->
mergeSettings
(
$existing
,
$vars
);
self
::
compatAddSetting
(
$resourcesObject
,
[
'vars'
=>
[
$nameSpace
=>
$vars
]],
$region
);
return
$resourcesObject
;
}
/**
* Add JavaScript variables to the root of the CRM object.
* This function is usually reserved for low-level system use.
* Extensions and components should generally use addVars instead.
*
* @param \CRM_Core_Resources $resourcesObject
* @param array $settings
* @param string $region
* The region to add settings to (eg. for payment processors usually billing-block
*
* @return CRM_Core_Resources
*/
public
static
function
compatAddSetting
(
$resourcesObject
,
$settings
,
$region
=
NULL
)
{
if
(
!
$region
)
{
$region
=
self
::
isAjaxMode
()
?
'ajax-snippet'
:
'html-header'
;
}
$resourcesObject
->
settings
=
$resourcesObject
->
mergeSettings
(
$resourcesObject
->
settings
,
$settings
);
if
(
isset
(
$resourcesObject
->
addedSettingsToRegion
[
$region
]))
{
return
$resourcesObject
;
}
$resources
=
$resourcesObject
;
$settingsResource
=
[
'callback'
=>
function
(
&
$snippet
,
&
$html
)
use
(
$resources
,
$region
)
{
$html
.
=
"
\n
"
.
self
::
compatRenderSetting
(
$resources
,
$region
);
},
'weight'
=>
-
100000
,
];
CRM_Core_Region
::
instance
(
$region
)
->
add
(
$settingsResource
);
$resourcesObject
->
addedSettingsToRegion
[
$region
]
=
TRUE
;
return
$resourcesObject
;
}
/**
* Helper fn for addSetting.
* Render JavaScript variables for the global CRM object.
*
* @param \CRM_Core_Resources $resourcesObject
*
* @return string
*/
public
static
function
compatRenderSetting
(
$resourcesObject
,
$region
)
{
// On a standard page request we construct the CRM object from scratch
if
(
$region
===
'html-header'
)
{
$js
=
'var CRM = '
.
json_encode
(
$resourcesObject
->
getSettings
())
.
';'
;
}
// For an ajax request we append to it
else
{
$js
=
'CRM.$.extend(true, CRM, '
.
json_encode
(
$resourcesObject
->
getSettings
())
.
');'
;
}
return
sprintf
(
"<script type=
\"
text/javascript
\"
>
\n
%s
\n
</script>
\n
"
,
$js
);
}
}
This diff is collapsed.
Click to expand it.
js/crm.payment.js
+
3
−
0
View file @
166cbd03
...
...
@@ -157,6 +157,9 @@
CRM
.
payment
=
payment
;
}
else
{
if
(
CRM
.
payment
.
hasOwnProperty
(
'
scriptName
'
)
&&
(
CRM
.
payment
.
scriptName
===
'
CRM.payment
'
))
{
return
;
}
if
(
CRM
.
payment
.
hasOwnProperty
(
'
getTotalAmount
'
))
{
delete
(
payment
.
getTotalAmount
);
payment
.
debugging
(
payment
.
scriptName
,
'
Deferring to client getTotalAmount function
'
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment