Skip to content

Commit 96c57fe

Browse files
committed
feat: add getter methods for css & js files
1 parent 11f5426 commit 96c57fe

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

core/components/modai/elements/plugins/modai.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
}
2222

2323
if (in_array($action, ['resource/create', 'resource/update'])) {
24-
$assetsUrl = $modAI->getOption('assetsUrl');
2524
$modx->controller->addLexiconTopic('modai:default');
2625

2726
$firstName = explode(' ', $modx->user->Profile->fullname)[0];
@@ -45,8 +44,7 @@
4544
</script>
4645
');
4746

48-
$lit = $modAI->getLit();
4947

50-
$modx->regClientCSS("{$assetsUrl}css/modai.css?lit=$lit");
51-
$modx->regClientStartupScript("{$assetsUrl}js/modai.js?lit=$lit");
48+
$modx->regClientCSS($modAI->getCSSFile());
49+
$modx->regClientStartupScript($modAI->getJSFile());
5250
}

core/components/modai/src/modAI.php

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,23 @@ function __construct(modX &$modx, array $config = [])
5353
*/
5454
public function getOption(string $key, $options = [], $default = null)
5555
{
56-
$option = $default;
57-
if (!empty($key) && is_string($key)) {
58-
if ($options != null && array_key_exists($key, $options)) {
59-
$option = $options[$key];
60-
} elseif (array_key_exists($key, $this->config)) {
61-
$option = $this->config[$key];
62-
} elseif (array_key_exists("{$this->namespace}.{$key}", $this->modx->config)) {
63-
$option = $this->modx->getOption("{$this->namespace}.{$key}");
64-
}
56+
if (empty($key) || !is_string($key)) {
57+
return $default;
6558
}
66-
return $option;
59+
60+
if (!empty($options) && array_key_exists($key, $options)) {
61+
return $options[$key];
62+
}
63+
64+
if (array_key_exists($key, $this->config)) {
65+
return $this->config[$key];
66+
}
67+
68+
if (array_key_exists("{$this->namespace}.{$key}", $this->modx->config)) {
69+
return $this->modx->getOption("{$this->namespace}.{$key}");
70+
}
71+
72+
return $default;
6773
}
6874

6975
public function getListOfTVs()
@@ -126,4 +132,20 @@ public function getAPIUrl()
126132
{
127133
return $this->config['assetsUrl'] . 'api.php';
128134
}
135+
136+
public function getJSFile()
137+
{
138+
$lit = $this->getLit();
139+
$assetsUrl = $this->getOption('assetsUrl');
140+
141+
return "{$assetsUrl}js/modai.js?lit=$lit";
142+
}
143+
144+
public function getCSSFile()
145+
{
146+
$lit = $this->getLit();
147+
$assetsUrl = $this->getOption('assetsUrl');
148+
149+
return "{$assetsUrl}css/modai.css?lit=$lit";
150+
}
129151
}

0 commit comments

Comments
 (0)