Skip to content

Commit 27fa72d

Browse files
authored
[BUGFIX] Fix f:mark.contentArea in v14 (#77)
Before this patch ContentAreaClosure would not be instantiate.
1 parent abd8e17 commit 27fa72d

3 files changed

Lines changed: 40 additions & 3 deletions

File tree

Classes/ViewHelpers/Mark/ContentAreaViewHelper.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
namespace TYPO3\CMS\VisualEditor\ViewHelpers\Mark;
66

7-
use Exception;
87
use B13\Container\Tca\Registry;
8+
use Exception;
99
use InvalidArgumentException;
1010
use Psr\Http\Message\ServerRequestInterface;
1111
use TYPO3\CMS\Backend\Utility\BackendUtility;
1212
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
1313
use TYPO3\CMS\Core\Information\Typo3Version;
14+
use TYPO3\CMS\Core\Page\ContentAreaClosure;
1415
use TYPO3\CMS\Core\Utility\GeneralUtility;
1516
use TYPO3\CMS\Frontend\Page\PageInformation;
1617
use TYPO3\CMS\VisualEditor\BackwardsCompatibility\ContentArea;
@@ -64,6 +65,11 @@ public function render(): string
6465
$renderingContext = $this->renderingContext ?? throw new InvalidArgumentException('$this->renderingContext is not available', 1772464212);
6566
$request = $renderingContext->getAttribute(ServerRequestInterface::class);
6667

68+
$renderedContentArea = $this->renderChildren();
69+
if (!$this->editModeService->isEditMode($request)) {
70+
return $renderedContentArea;
71+
}
72+
6773
$this->editModeService->init($request);
6874

6975
$additionalArguments = $this->arguments;
@@ -74,7 +80,7 @@ public function render(): string
7480

7581
$event = $this->eventDispatcher->dispatch(
7682
new RenderContentAreaEvent(
77-
renderedContentArea: $this->renderChildren(),
83+
renderedContentArea: $renderedContentArea,
7884
contentArea: $this->getContentArea($request, $colPos, $txContainerParent),
7985
request: $request,
8086
),
@@ -109,8 +115,15 @@ private function getContentArea(ServerRequestInterface $request, int $colPos, in
109115
/** @var PageInformation $pageInformation */
110116
$pageInformation = $request->getAttribute('frontend.page.information');
111117
$pageLayout = $pageInformation->getPageLayout() ?? throw new InvalidArgumentException('PageLayout is not available', 1772464283);
112-
foreach ($pageLayout->getContentAreas() as $contentArea) {
118+
$contentAreaCollection = $pageLayout->getContentAreas();
119+
if ($this->typo3Version->getMajorVersion() >= 14) {
120+
$contentAreaCollection = $contentAreaCollection->withRequest($request);
121+
}
122+
123+
foreach ($contentAreaCollection as $contentArea) {
113124
if ($this->typo3Version->getMajorVersion() >= 14) {
125+
$contentArea = $contentArea instanceof ContentAreaClosure ? $contentArea->instantiate($request) : $contentArea;
126+
114127
$contentAreaColPos = $contentArea->getColPos();
115128
$name = $contentArea->getName();
116129
/** @var list<string> $allowed */

phpstan-baseline-13.neon

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,24 @@ parameters:
144144
count: 1
145145
path: Classes/ViewHelpers/ImageViewHelper.php
146146

147+
-
148+
message: '#^Call to method instantiate\(\) on an unknown class TYPO3\\CMS\\Core\\Page\\ContentAreaClosure\.$#'
149+
identifier: class.notFound
150+
count: 1
151+
path: Classes/ViewHelpers/Mark/ContentAreaViewHelper.php
152+
153+
-
154+
message: '#^Cannot call method withRequest\(\) on array\.$#'
155+
identifier: method.nonObject
156+
count: 1
157+
path: Classes/ViewHelpers/Mark/ContentAreaViewHelper.php
158+
159+
-
160+
message: '#^Class TYPO3\\CMS\\Core\\Page\\ContentAreaClosure not found\.$#'
161+
identifier: class.notFound
162+
count: 1
163+
path: Classes/ViewHelpers/Mark/ContentAreaViewHelper.php
164+
147165
-
148166
message: '#^Property TYPO3Fluid\\Fluid\\Core\\ViewHelper\\AbstractViewHelper\:\:\$renderingContext \(TYPO3Fluid\\Fluid\\Core\\Rendering\\RenderingContextInterface\) on left side of \?\? is not nullable\.$#'
149167
identifier: nullCoalesce.property

phpstan-baseline-14.neon

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ parameters:
5454
count: 1
5555
path: Classes/ViewHelpers/Mark/ContentAreaViewHelper.php
5656

57+
-
58+
message: '#^Instanceof between TYPO3\\CMS\\Core\\Page\\ContentArea and TYPO3\\CMS\\Core\\Page\\ContentAreaClosure will always evaluate to false\.$#'
59+
identifier: instanceof.alwaysFalse
60+
count: 1
61+
path: Classes/ViewHelpers/Mark/ContentAreaViewHelper.php
62+
5763
-
5864
message: '#^Property TYPO3\\CMS\\VisualEditor\\ViewHelpers\\Render\\TextViewHelper\:\:\$typo3Version on left side of \?\? is not nullable nor uninitialized\.$#'
5965
identifier: nullCoalesce.initializedProperty

0 commit comments

Comments
 (0)