Skip to content

Commit bda1992

Browse files
committed
[TASK] Cleanup viewhelpers
1 parent 4f6bc9d commit bda1992

File tree

6 files changed

+44
-190
lines changed

6 files changed

+44
-190
lines changed

Build/phpstan-baseline-v13.neon

Lines changed: 0 additions & 145 deletions
This file was deleted.

Build/phpstan.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ includes:
33
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-strict-rules/rules.neon
44
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-deprecation-rules/rules.neon
55
- %currentWorkingDirectory%/.build/vendor/friendsoftypo3/phpstan-typo3/extension.neon
6-
- %currentWorkingDirectory%/Build/phpstan-baseline-v13.neon
76

87
parameters:
98
level: 8

Classes/ViewHelpers/Data/PaginateViewHelper.php

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
use TYPO3\CMS\Core\Pagination\SimplePagination;
1515
use TYPO3\CMS\Core\Utility\ArrayUtility;
1616
use TYPO3\CMS\Core\Utility\GeneralUtility;
17+
use TYPO3\CMS\Core\View\ViewFactoryData;
18+
use TYPO3\CMS\Core\View\ViewFactoryInterface;
19+
use TYPO3\CMS\Core\View\ViewInterface;
1720
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
1821
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
1922
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
2023
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
21-
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
22-
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
23-
use TYPO3\CMS\Fluid\View\StandaloneView;
2424
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
2525
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
2626

@@ -34,6 +34,11 @@ class PaginateViewHelper extends AbstractViewHelper
3434
*/
3535
protected $escapeOutput = false;
3636

37+
public function __construct(
38+
protected readonly ViewFactoryInterface $viewFactory,
39+
) {
40+
}
41+
3742
public function initializeArguments(): void
3843
{
3944
parent::initializeArguments();
@@ -78,7 +83,7 @@ public function render(): string
7883
'pagination' => $pagination,
7984
'configuration' => $configuration,
8085
]);
81-
$paginationRendered = $paginationView->render();
86+
$paginationRendered = $paginationView->render('Paginate/Index');
8287

8388
$variableProvider = $renderingContext->getVariableProvider();
8489
$variableProvider->add('paginator', $paginator);
@@ -99,20 +104,10 @@ public function render(): string
99104
);
100105
}
101106

102-
protected function getTemplateObject(RenderingContextInterface $renderingContext, ServerRequestInterface $request): StandaloneView
107+
protected function getTemplateObject(RenderingContextInterface $renderingContext, ServerRequestInterface $request): ViewInterface
103108
{
104109
$setup = $this->getConfigurationManager()->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
105110

106-
/** @phpstan-ignore-next-line */
107-
$context = GeneralUtility::makeInstance(RenderingContextFactory::class)->create([], $request);
108-
if ((new \ReflectionMethod(RenderingContextFactory::class, 'create'))->getNumberOfParameters() === 1) {
109-
/** @phpstan-ignore-next-line */
110-
$context->setRequest($request);
111-
}
112-
113-
/** @var StandaloneView $view */
114-
$view = GeneralUtility::makeInstance(StandaloneView::class, $context);
115-
116111
$layoutRootPaths = [];
117112
$layoutRootPaths[] = GeneralUtility::getFileAbsFileName('EXT:bootstrap_package/Resources/Private/Layouts/ViewHelpers/');
118113
if (isset($setup['plugin.']['tx_bootstrappackage.']['view.']['layoutRootPaths.'])) {
@@ -135,12 +130,12 @@ protected function getTemplateObject(RenderingContextInterface $renderingContext
135130
}
136131
}
137132

138-
$view->setLayoutRootPaths($layoutRootPaths);
139-
$view->setPartialRootPaths($partialRootPaths);
140-
$view->setTemplateRootPaths($templateRootPaths);
141-
$view->setTemplate('Paginate/Index');
142-
143-
return $view;
133+
return $this->viewFactory->create(new ViewFactoryData(
134+
templateRootPaths: $templateRootPaths,
135+
partialRootPaths: $partialRootPaths,
136+
layoutRootPaths: $layoutRootPaths,
137+
request: $request,
138+
));
144139
}
145140

146141
protected function getConfigurationManager(): ConfigurationManagerInterface
@@ -155,9 +150,6 @@ protected function getRequestFromRenderingContext(RenderingContextInterface $ren
155150
{
156151
if ($renderingContext->hasAttribute(ServerRequestInterface::class)) {
157152
return $renderingContext->getAttribute(ServerRequestInterface::class);
158-
} elseif ($renderingContext instanceof RenderingContext) {
159-
/** @phpstan-ignore-next-line */
160-
return $renderingContext->getRequest();
161153
}
162154

163155
return null;

Classes/ViewHelpers/FrameViewHelper.php

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010
namespace BK2K\BootstrapPackage\ViewHelpers;
1111

1212
use BK2K\BootstrapPackage\Utility\ImageVariantsUtility;
13+
use Psr\Http\Message\ServerRequestInterface;
1314
use TYPO3\CMS\Core\Resource\File;
1415
use TYPO3\CMS\Core\Resource\FileReference;
1516
use TYPO3\CMS\Core\Resource\ResourceFactory;
1617
use TYPO3\CMS\Core\Utility\GeneralUtility;
18+
use TYPO3\CMS\Core\View\ViewFactoryData;
19+
use TYPO3\CMS\Core\View\ViewFactoryInterface;
20+
use TYPO3\CMS\Core\View\ViewInterface;
1721
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
1822
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
19-
use TYPO3\CMS\Fluid\View\StandaloneView;
23+
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
2024
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
2125

2226
/**
@@ -29,6 +33,11 @@ class FrameViewHelper extends AbstractViewHelper
2933
*/
3034
protected $escapeOutput = false;
3135

36+
public function __construct(
37+
protected readonly ViewFactoryInterface $viewFactory,
38+
) {
39+
}
40+
3241
public function initializeArguments(): void
3342
{
3443
parent::initializeArguments();
@@ -144,7 +153,7 @@ public function render()
144153
);
145154

146155
// Template
147-
$view = self::getTemplateObject();
156+
$view = $this->getTemplateObject();
148157
$view->assignMultiple(
149158
[
150159
'id' => $identifier,
@@ -162,10 +171,10 @@ public function render()
162171
]
163172
);
164173

165-
return $view->render();
174+
return $view->render('Frame/Index');
166175
}
167176

168-
protected static function getTemplateObject(): StandaloneView
177+
protected function getTemplateObject(): ViewInterface
169178
{
170179
$setup = static::getConfigurationManager()->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
171180

@@ -191,14 +200,12 @@ protected static function getTemplateObject(): StandaloneView
191200
}
192201
}
193202

194-
/** @var StandaloneView $view */
195-
$view = GeneralUtility::makeInstance(StandaloneView::class);
196-
$view->setLayoutRootPaths($layoutRootPaths);
197-
$view->setPartialRootPaths($partialRootPaths);
198-
$view->setTemplateRootPaths($templateRootPaths);
199-
$view->setTemplate('Frame/Index');
200-
201-
return $view;
203+
return $this->viewFactory->create(new ViewFactoryData(
204+
templateRootPaths: $templateRootPaths,
205+
partialRootPaths: $partialRootPaths,
206+
layoutRootPaths: $layoutRootPaths,
207+
request: $this->getRequestFromRenderingContext($this->renderingContext),
208+
));
202209
}
203210

204211
protected static function getConfigurationManager(): ConfigurationManagerInterface
@@ -208,4 +215,13 @@ protected static function getConfigurationManager(): ConfigurationManagerInterfa
208215

209216
return $configurationManager;
210217
}
218+
219+
protected function getRequestFromRenderingContext(RenderingContextInterface $renderingContext): ?ServerRequestInterface
220+
{
221+
if ($renderingContext->hasAttribute(ServerRequestInterface::class)) {
222+
return $renderingContext->getAttribute(ServerRequestInterface::class);
223+
}
224+
225+
return null;
226+
}
211227
}

Classes/ViewHelpers/Link/PaginateViewHelper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use TYPO3\CMS\Core\Http\ApplicationType;
1414
use TYPO3\CMS\Core\Utility\GeneralUtility;
1515
use TYPO3\CMS\Core\Utility\HttpUtility;
16-
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
1716
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
1817
use TYPO3\CMS\Frontend\Typolink\LinkFactory;
1918
use TYPO3\CMS\Frontend\Typolink\UnableToLinkException;
@@ -95,9 +94,6 @@ protected function getRequestFromRenderingContext(RenderingContextInterface $ren
9594
{
9695
if ($renderingContext->hasAttribute(ServerRequestInterface::class)) {
9796
return $renderingContext->getAttribute(ServerRequestInterface::class);
98-
} elseif ($renderingContext instanceof RenderingContext) {
99-
/** @phpstan-ignore-next-line */
100-
return $renderingContext->getRequest();
10197
}
10298

10399
return null;

Classes/ViewHelpers/TypoScript/ConstantViewHelper.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
use BK2K\BootstrapPackage\Utility\TypoScriptUtility;
1414
use Psr\Http\Message\ServerRequestInterface;
15-
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
1615
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
1716
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
1817

@@ -53,9 +52,6 @@ protected function getRequestFromRenderingContext(RenderingContextInterface $ren
5352
{
5453
if ($renderingContext->hasAttribute(ServerRequestInterface::class)) {
5554
return $renderingContext->getAttribute(ServerRequestInterface::class);
56-
} elseif ($renderingContext instanceof RenderingContext) {
57-
/** @phpstan-ignore-next-line */
58-
return $renderingContext->getRequest();
5955
}
6056

6157
return null;

0 commit comments

Comments
 (0)