Skip to content

Commit

Permalink
Merge pull request #19 from Fohn-Group/allow-js-package-version-selec…
Browse files Browse the repository at this point in the history
…tion

Allow specifying version of fohn-js and jQuery in Page.
  • Loading branch information
ibelar authored Sep 7, 2023
2 parents 757590a + 5812f53 commit 23ee4be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ class Page extends View
public string $title = '';
protected ?Layout $layout = null;

/** Used a specific js package version, ex: '1.5.0', a wildcard or leave empty for latest. */
public string $fohnJsVersion = '^1';
public string $jQueryVersion = '^3';

public ?string $toastSelector = '#fohn-toast';
public string $jsBundleLocation = '/public';

/** An array of Js packages to include in Page. */
public array $jsPackages = [
'jquery' => [
'url' => 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js',
'url' => 'https://unpkg.com/jquery',
],
'fohn-js' => [
'url' => 'https://unpkg.com/fohn-ui@1.5.0/dist/fohn-ui.min.js',
'url' => 'https://unpkg.com/fohn-ui',
],
];

Expand All @@ -60,6 +64,14 @@ protected function initRenderTree(): void
{
parent::initRenderTree();

if ($this->fohnJsVersion) {
$this->includeJsPackage('fohn-js', 'https://unpkg.com/fohn-ui@' . $this->fohnJsVersion);
}

if ($this->jQueryVersion) {
$this->includeJsPackage('jquery', 'https://unpkg.com/jquery@' . $this->jQueryVersion);
}

Ui::theme()::styleAs(Base::PAGE, [$this]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Service/Atk/FormControlFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function factorySelect(Field $field): Control
$control->onSetValue(function ($value) use ($refModel) {
if ($value) {
$refEntity = $refModel->tryLoad($value);
if ($refEntity->isLoaded()) {
if ($refEntity) {
$selectableItems[$value] = $refEntity->get($refEntity->titleField);
}
}
Expand All @@ -236,7 +236,7 @@ protected function factorySelect(Field $field): Control
$items = self::getSelectItems($refModel);
if ($value && !in_array($value, array_column($items, Control\Select::KEY), true)) {
$refEntity = $refModel->tryLoad($value);
if ($refEntity->isLoaded()) {
if ($refEntity) {
$newItems = [Control\Select::KEY => $value, Control\Select::LABEL => $refEntity->get($refEntity->titleField)];
array_unshift($items, $newItems);
}
Expand Down

0 comments on commit 23ee4be

Please sign in to comment.