1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace nystudio107\instantanalytics\variables; |
4
|
|
|
|
5
|
|
|
use nystudio107\instantanalytics\helpers\Manifest as ManifestHelper; |
6
|
|
|
|
7
|
|
|
use craft\helpers\Template; |
8
|
|
|
|
9
|
|
|
use yii\base\InvalidConfigException; |
10
|
|
|
use yii\web\NotFoundHttpException; |
11
|
|
|
|
12
|
|
|
use Twig\Markup; |
13
|
|
|
|
14
|
|
|
class ManifestVariable |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
// Public Methods |
17
|
|
|
// ========================================================================= |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Get the passed in JS modules from the manifest, and register them in the current Craft view |
21
|
|
|
* |
22
|
|
|
* @param array $modules |
|
|
|
|
23
|
|
|
* @throws InvalidConfigException |
|
|
|
|
24
|
|
|
* @throws NotFoundHttpException |
|
|
|
|
25
|
|
|
*/ |
|
|
|
|
26
|
|
|
public function registerJsModules(array $modules) |
27
|
|
|
{ |
28
|
|
|
ManifestHelper::registerJsModules($modules); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Get the passed in CS modules from the manifest, and register them in the current Craft view |
33
|
|
|
* |
34
|
|
|
* @param array $modules |
|
|
|
|
35
|
|
|
* @throws InvalidConfigException |
|
|
|
|
36
|
|
|
* @throws NotFoundHttpException |
|
|
|
|
37
|
|
|
*/ |
|
|
|
|
38
|
|
|
public function registerCssModules(array $modules) |
39
|
|
|
{ |
40
|
|
|
ManifestHelper::registerCssModules($modules); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the passed in JS module from the manifest, then output a `<script src="">` tag for it in the HTML |
45
|
|
|
* |
46
|
|
|
* @param string $moduleName |
|
|
|
|
47
|
|
|
* @param bool $async |
|
|
|
|
48
|
|
|
* @param null|array $config |
|
|
|
|
49
|
|
|
* |
50
|
|
|
* @return null|Markup |
51
|
|
|
* @throws NotFoundHttpException |
52
|
|
|
*/ |
53
|
|
|
public function includeJsModule(string $moduleName, bool $async = false) |
54
|
|
|
{ |
55
|
|
|
return Template::raw( |
56
|
|
|
ManifestHelper::includeJsModule($moduleName, $async) ?? '' |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get the passed in CS module from the manifest, then output a `<link>` tag for it in the HTML |
62
|
|
|
* |
63
|
|
|
* @param string $moduleName |
|
|
|
|
64
|
|
|
* @param bool $async |
|
|
|
|
65
|
|
|
* @param null|array $config |
|
|
|
|
66
|
|
|
* |
67
|
|
|
* @return Markup |
68
|
|
|
* @throws NotFoundHttpException |
69
|
|
|
*/ |
70
|
|
|
public function includeCssModule(string $moduleName, bool $async = false): Markup |
71
|
|
|
{ |
72
|
|
|
return Template::raw( |
73
|
|
|
ManifestHelper::includeCssModule($moduleName, $async) ?? '' |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|