Skip to content

Commit

Permalink
[TASK] Use JS module loader instead of requirejs when available
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Dec 9, 2024
1 parent a167840 commit bb189a1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public function requireColumnPositionJavaScript() : void
{
/** @var PageRenderer $pageRenderer */
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Flux/FluxColPosAssignment');
if (method_exists($pageRenderer, 'loadJavaScriptModule')) {
$pageRenderer->loadJavaScriptModule('@fluidtypo3/flux/FluxColPosAssignment.js');
} else {
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Flux/FluxColPosAssignment');
}
}
}
6 changes: 5 additions & 1 deletion Classes/Integration/PreviewRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ protected function attachAssets(): void
{
if (!static::$assetsIncluded) {
$this->pageRenderer->addCssFile('EXT:flux/Resources/Public/css/flux.css');
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Flux/FluxCollapse');
if (method_exists($this->pageRenderer, 'loadJavaScriptModule')) {
$this->pageRenderer->loadJavaScriptModule('@fluidtypo3/flux/FluxCollapse.js');
} else {
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Flux/FluxCollapse');
}

static::$assetsIncluded = true;
}
Expand Down
8 changes: 8 additions & 0 deletions Configuration/JavaScriptModules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'dependencies' => ['core', 'backend'],
'imports' => [
'@fluidtypo3/flux/' => 'EXT:flux/Resources/Public/JavaScript/',
]
];
12 changes: 10 additions & 2 deletions Tests/Unit/Integration/PreviewRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@
use FluidTYPO3\Flux\Provider\ProviderResolver;
use FluidTYPO3\Flux\Tests\Unit\AbstractTestCase;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;

class PreviewRendererTest extends AbstractTestCase
{
private PageRenderer $pageRenderer;
private ProviderResolver $providerResolver;
private string $registerMethodName;

protected function setUp(): void
{
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '13.4', '>=')) {
$this->registerMethodName = 'loadJavaScriptModule';
} else {
$this->registerMethodName = 'loadRequireJsModule';
}

$this->pageRenderer = $this->getMockBuilder(PageRenderer::class)
->onlyMethods(['loadRequireJsModule'])
->onlyMethods([$this->registerMethodName])
->disableOriginalConstructor()
->getMock();
$this->providerResolver = $this->getMockBuilder(ProviderResolver::class)
Expand Down Expand Up @@ -56,7 +64,7 @@ public function testPreProcess(): void

public function testAttachAssets(): void
{
$this->pageRenderer->expects($this->atLeastOnce())->method('loadRequireJsModule');
$this->pageRenderer->expects($this->atLeastOnce())->method($this->registerMethodName);
$subject = new PreviewRenderer($this->pageRenderer, $this->providerResolver);
$this->callInaccessibleMethod($subject, 'attachAssets');
}
Expand Down

0 comments on commit bb189a1

Please sign in to comment.