Commit 03c0c741 authored by Susanne Moog's avatar Susanne Moog Committed by Christian Kuhn
Browse files

[BUGFIX] Do not overwrite previously set preview mode

The frontend preview aspect may be set from the admin panel
or the frontend extension or even from a third-party extension
in a middleware. The previous implementation overwrote the preview
settings on every initialisation, resulting in lost preview
information. Instead of overwriting the setting, this change takes
the current preview value into account - if the preview was enabled
by a previous instance this is kept.

Additionally, the logic to set the preview flag in both frontend
and admin panel has been streamlined.

Resolves: #91225
Releases: main, 11.5
Change-Id: I9f642bca1928638cac5eb5c1468710f5fad28137
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72825


Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent fc31824a
......@@ -168,9 +168,6 @@ class PreviewModule extends AbstractModule implements RequestEnricherInterface,
$context = GeneralUtility::makeInstance(Context::class);
$this->clearPreviewSettings($context);
// Set preview flag
$context->setAspect('frontend.preview', GeneralUtility::makeInstance(PreviewAspect::class, true));
// Modify visibility settings (hidden pages + hidden content)
$context->setAspect(
'visibility',
......@@ -209,9 +206,13 @@ class PreviewModule extends AbstractModule implements RequestEnricherInterface,
)
);
}
if (!$simulateUserGroup && !$simTime && !$showHiddenPages && !$showHiddenRecords) {
$context->setAspect('frontend.preview', GeneralUtility::makeInstance(PreviewAspect::class));
$isPreview = $simulateUserGroup || $simTime || $showHiddenPages || $showHiddenRecords;
if ($context->hasAspect('frontend.preview')) {
$existingPreviewAspect = $context->getAspect('frontend.preview');
$isPreview = $existingPreviewAspect->isPreview() || $isPreview;
}
$previewAspect = GeneralUtility::makeInstance(PreviewAspect::class, $isPreview);
$context->setAspect('frontend.preview', $previewAspect);
}
/**
......
......@@ -89,6 +89,9 @@ class PreviewModuleTest extends UnitTestCase
$configurationService->getConfigurationOption('preview', 'showFluidDebug')->willReturn('0');
$configurationService->getConfigurationOption('preview', 'simulateUserGroup')->willReturn('1');
$context = $this->prophesize(Context::class);
$context->hasAspect('frontend.preview')->willReturn(false);
$context->setAspect('date', Argument::any())->hasReturnVoid();
$context->setAspect('visibility', Argument::any())->hasReturnVoid();
GeneralUtility::setSingletonInstance(Context::class, $context->reveal());
GeneralUtility::setSingletonInstance(ConfigurationService::class, $configurationService->reveal());
......@@ -97,5 +100,6 @@ class PreviewModuleTest extends UnitTestCase
$previewModule->enrich($request->reveal());
$context->setAspect('frontend.user', Argument::any())->shouldHaveBeenCalled();
$context->setAspect('frontend.preview', Argument::any())->shouldHaveBeenCalled();
}
}
......@@ -34,10 +34,7 @@ use TYPO3\CMS\Frontend\Aspect\PreviewAspect;
*/
class PreviewSimulator implements MiddlewareInterface
{
/**
* @var \TYPO3\CMS\Core\Context\Context
*/
private $context;
private Context $context;
public function __construct(Context $context)
{
......@@ -54,11 +51,15 @@ class PreviewSimulator implements MiddlewareInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if ((bool)$this->context->getPropertyFromAspect('backend.user', 'isLoggedIn', false)) {
if ($this->context->getPropertyFromAspect('backend.user', 'isLoggedIn', false)) {
$simulatingDate = $this->simulateDate($request);
$simulatingGroup = $this->simulateUserGroup($request);
$showHiddenRecords = ($this->context->hasAspect('visibility') ? $this->context->getAspect('visibility')->includeHidden() : false);
$isPreview = (int)($simulatingDate || $simulatingGroup || $showHiddenRecords);
$isPreview = $simulatingDate || $simulatingGroup || $showHiddenRecords;
if ($this->context->hasAspect('frontend.preview')) {
$previewAspect = $this->context->getAspect('frontend.preview');
$isPreview = $previewAspect->isPreview() || $isPreview;
}
$previewAspect = GeneralUtility::makeInstance(PreviewAspect::class, $isPreview);
$this->context->setAspect('frontend.preview', $previewAspect);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment