Skip to content

Commit

Permalink
[BUGFIX] Fix collapse script integration (FluidTYPO3#1829)
Browse files Browse the repository at this point in the history
Fixes the inclusion of the content area collaps script,
and improves the integration by avoiding the creation
of a ModuleTemplate which internally creates a view,
by replacing it with simple asset inclusions which was
the only feature from ModuleTemplate that was needed.

Close: FluidTYPO3#1820
  • Loading branch information
NamelessCoder authored Sep 12, 2020
1 parent b7955ac commit 16d8f9b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 36 deletions.
10 changes: 0 additions & 10 deletions Classes/Integration/HookSubscribers/ContentIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ public function addSubIcon(array $parameters, $caller = null)
return '';
}

$this->attachAssets();

$provider = null;
$icon = '';
$record = null === $record && 0 < $uid ? BackendUtility::getRecord($table, $uid) : $record;
Expand Down Expand Up @@ -203,12 +201,4 @@ protected function detectFirstFlexTypeFieldInTableFromPossibilities($table, $fie
}
return null;
}

/**
* @return void
*/
protected function attachAssets()
{
$GLOBALS['TBE_STYLES']['stylesheet'] = 'EXT:flux/Resources/Public/css/flux.css';
}
}
24 changes: 3 additions & 21 deletions Classes/Integration/HookSubscribers/Preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@

use FluidTYPO3\Flux\Provider\ProviderInterface;
use FluidTYPO3\Flux\Service\FluxService;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;

/**
Expand Down Expand Up @@ -69,24 +66,9 @@ public function preProcess(PageLayoutView &$parentObject, &$drawItem, &$headerCo
protected function attachAssets()
{
if (false === static::$assetsIncluded) {
$doc = GeneralUtility::makeInstance(ModuleTemplate::class);
$doc->backPath = $GLOBALS['BACK_PATH'] ?? '';

/** @var PageRenderer $pageRenderer */
$pageRenderer = $doc->getPageRenderer();

$fullJsPath = PathUtility::getRelativePath(
defined('PATH_typo3') ? PATH_typo3 : Environment::getPublicPath(),
GeneralUtility::getFileAbsFileName('EXT:flux/Resources/Public/js/')
);

// requirejs
$pageRenderer->addRequireJsConfiguration([
'paths' => [
'FluidTypo3/Flux/FluxCollapse' => $fullJsPath . 'fluxCollapse',
],
]);
$pageRenderer->loadRequireJsModule('FluidTypo3/Flux/FluxCollapse');
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addCssFile('EXT:flux/Resources/Public/css/flux.css');
$pageRenderer->loadRequireJsModule('TYPO3/CMS/Flux/FluxCollapse');

static::$assetsIncluded = true;
}
Expand Down
File renamed without changes.
9 changes: 4 additions & 5 deletions Tests/Unit/Integration/HookSubscribers/PreviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ protected function callUserFunction($function, $caller)
*/
public function testAttachAssets()
{
$pageRenderer = $this->getMockBuilder(PageRenderer::class)->setMethods(['addRequireJsConfiguration', 'loadRequireJsModule'])->getMock();
$pageRenderer->expects($this->atLeastOnce())->method('addRequireJsConfiguration');
$pageRenderer = $this->getMockBuilder(PageRenderer::class)->setMethods(['loadRequireJsModule'])->getMock();
$pageRenderer->expects($this->atLeastOnce())->method('loadRequireJsModule');
$document = $this->getMockBuilder(ModuleTemplate::class)->setMethods(['getPageRenderer'])->getMock();
$document->expects($this->once())->method('getPageRenderer')->willReturn($pageRenderer);
GeneralUtility::addInstance(ModuleTemplate::class, $document);
$instances = GeneralUtility::getSingletonInstances();
GeneralUtility::setSingletonInstance(PageRenderer::class, $pageRenderer);
$subject = $this->createInstance();
$this->callInaccessibleMethod($subject, 'attachAssets');
GeneralUtility::resetSingletonInstances($instances);
}
}

0 comments on commit 16d8f9b

Please sign in to comment.