- Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathScript.php
More file actions
41 lines (36 loc) · 1.25 KB
/
Script.php
File metadata and controls
41 lines (36 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace RatePAY\Payment\Helper;
class Script extends \Magento\Framework\App\Helper\AbstractHelper
{
/**
* @var \Magento\Framework\App\ProductMetadata
*/
protected $productMetadata;
/**
* Payment constructor.
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Framework\App\ProductMetadata $productMetadata
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\App\ProductMetadata $productMetadata
) {
parent::__construct($context);
$this->productMetadata = $productMetadata;
}
/**
* This handles inserting JavaScript which has to be done different sind Magento 2.4.7
*
* @param string $script
* @return string
*/
public function insertScript($script)
{
if (version_compare($this->productMetadata->getVersion(), '2.4.7', '>=')) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$secureRenderer = $objectManager->create(\Magento\Framework\View\Helper\SecureHtmlRenderer::class);
return $secureRenderer->renderTag('script', [], $script, false);
}
return "<script>".$script."</script>";
}
}