Skip to content

Commit 567c7ef

Browse files
Vendy Tjunghelhum
authored andcommitted
Update to 9.5 (with middleware)
1 parent c3ee22d commit 567c7ef

4 files changed

Lines changed: 114 additions & 31 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
namespace Helhum\TyposcriptRendering\Middleware;
3+
4+
/*
5+
* This file is part of the TypoScript Rendering TYPO3 extension.
6+
*
7+
* It is free software; you can redistribute it and/or modify it under
8+
* the terms of the GNU General Public License, either version 2
9+
* of the License, or any later version.
10+
*
11+
* For the full copyright and license information, please read
12+
* LICENSE file that was distributed with this source code.
13+
*
14+
*/
15+
16+
use Psr\Http\Message\ResponseInterface;
17+
use Psr\Http\Message\ServerRequestInterface;
18+
use Psr\Http\Server\MiddlewareInterface;
19+
use Psr\Http\Server\RequestHandlerInterface;
20+
use TYPO3\CMS\Core\Exception;
21+
use TYPO3\CMS\Core\Http\Response;
22+
use TYPO3\CMS\Core\Utility\GeneralUtility;
23+
24+
/**
25+
* Lightweight alternative to regular frontend requests based at typoscript_rendering extensions; used when $_GET[tx_typoscriptrendering] is set.
26+
*/
27+
class TypoScriptRenderingHandler implements MiddlewareInterface
28+
{
29+
/**
30+
* Dispatches the request to the corresponding typoscript_rendering configuration
31+
*
32+
* @param ServerRequestInterface $request
33+
* @param RequestHandlerInterface $handler
34+
* @throws Exception
35+
* @return ResponseInterface
36+
*/
37+
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
38+
{
39+
$TsRendering = $request->getParsedBody()['tx_typoscriptrendering'] ?? $request->getQueryParams()['tx_typoscriptrendering'] ?? null;
40+
41+
if ($TsRendering === null) {
42+
return $handler->handle($request);
43+
}
44+
45+
// Remove any output produced until now
46+
ob_clean();
47+
48+
//prepare and return final output
49+
$GLOBALS['TSFE']->INTincScript();
50+
51+
$response = GeneralUtility::makeInstance(Response::class);
52+
53+
$response->getBody()->write($GLOBALS['TSFE']->content);
54+
55+
return $response;
56+
}
57+
}

Classes/ViewHelpers/Uri/AjaxActionViewHelper.php

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,38 +38,51 @@ class AjaxActionViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractView
3838
protected $configurationManager;
3939

4040
/**
41-
* @param string $action Target action
42-
* @param array $arguments Arguments
43-
* @param string $controller Target controller in UpperCamelCase. If null, current controllerName is used.
44-
* @param string $extensionName Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used
45-
* @param string $pluginName Target plugin. If empty, the current plugin name is used
46-
* @param int $pageUid target page. See TypoLink destination
47-
* @param string $section the anchor to be added to the URI
48-
* @param string $format The requested format, e.g. ".html
49-
* @param bool $linkAccessRestrictedPages If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.
50-
* @param array $additionalParams additional query parameters that won't be prefixed like $arguments (overrule $arguments)
51-
* @param bool $absolute If set, an absolute URI is rendered
52-
* @param bool $addQueryString If set, the current query parameters will be kept in the URI
53-
* @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the URI. Only active if $addQueryString = TRUE
54-
* @param string $addQueryStringMethod Set which parameters will be kept. Only active if $addQueryString = TRUE
55-
* @param string $contextRecord The record that the rendering should depend upon. e.g. current (default: record is fetched from current Extbase plugin), tt_content:12 (tt_content record with uid 12), pages:15 (pages record with uid 15), 'currentPage' record of current page
41+
* Initialize arguments
42+
*
43+
* @api
44+
*/
45+
public function initializeArguments()
46+
{
47+
$this->registerArgument('action', 'string', 'Target action');
48+
$this->registerArgument('arguments', 'array', 'Arguments', false, []);
49+
$this->registerArgument('controller', 'string', 'Target controller. If NULL current controllerName is used');
50+
$this->registerArgument('extensionName', 'string', 'Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used');
51+
$this->registerArgument('pluginName', 'string', 'Target plugin. If empty, the current plugin name is used');
52+
$this->registerArgument('pageUid', 'int', 'Target page. See TypoLink destination');
53+
$this->registerArgument('section', 'string', 'The anchor to be added to the URI', false, '');
54+
$this->registerArgument('format', 'string', 'The requested format, e.g. ".html', false, '');
55+
$this->registerArgument('linkAccessRestrictedPages', 'bool', 'If set, links pointing to access restricted pages will still link to the page even though the page cannot be accessed.', false, false);
56+
$this->registerArgument('additionalParams', 'array', 'additional query parameters that won\'t be prefixed like $arguments (overrule $arguments)', false, []);
57+
$this->registerArgument('absolute', 'bool', 'If set, an absolute URI is rendered', false, false);
58+
$this->registerArgument('addQueryString', 'bool', 'If set, the current query parameters will be kept in the URI', false, false);
59+
$this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'arguments to be removed from the URI. Only active if $addQueryString = TRUE', false, []);
60+
$this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE');
61+
$this->registerArgument('contextRecord', 'string', 'The record that the rendering should depend upon. e.g. current (default: record is fetched from current Extbase plugin), tt_content:12 (tt_content record with uid 12), pages:15 (pages record with uid 15), \'currentPage\' record of current page', false, 'current');
62+
}
63+
64+
/**
5665
*
5766
* @throws \Helhum\TyposcriptRendering\Configuration\ConfigurationBuildingException
5867
* @return string Rendered link
5968
*
6069
*/
61-
public function render($action = null, array $arguments = [], $controller = null, $extensionName = null, $pluginName = null, $pageUid = null, $section = '', $format = '', $linkAccessRestrictedPages = false, array $additionalParams = [], $absolute = false, $addQueryString = false, array $argumentsToBeExcludedFromQueryString = [], $addQueryStringMethod = null, $contextRecord = 'current')
70+
public function render()
6271
{
72+
$pluginName = $this->arguments['pluginName'];
73+
$extensionName = $this->arguments['extensionName'];
74+
$contextRecord = $this->arguments['contextRecord'];
75+
6376
if ($pluginName === null) {
64-
$pluginName = $this->controllerContext->getRequest()->getPluginName();
77+
$pluginName = $this->renderingContext->getControllerContext()->getRequest()->getPluginName();
6578
}
6679
if ($extensionName === null) {
67-
$extensionName = $this->controllerContext->getRequest()->getControllerExtensionName();
80+
$extensionName = $this->renderingContext->getControllerContext()->getRequest()->getControllerExtensionName();
6881
}
6982
if ($contextRecord === 'current') {
7083
if (
71-
$pluginName !== $this->controllerContext->getRequest()->getPluginName()
72-
|| $extensionName !== $this->controllerContext->getRequest()->getControllerExtensionName()
84+
$pluginName !== $this->renderingContext->getControllerContext()->getRequest()->getPluginName()
85+
|| $extensionName !== $this->renderingContext->getControllerContext()->getRequest()->getControllerExtensionName()
7386
) {
7487
$contextRecord = 'currentPage';
7588
} else {
@@ -79,20 +92,20 @@ public function render($action = null, array $arguments = [], $controller = null
7992
$renderingConfiguration = $this->buildTypoScriptRenderingConfiguration($extensionName, $pluginName, $contextRecord);
8093
$additionalParams['tx_typoscriptrendering']['context'] = json_encode($renderingConfiguration);
8194

82-
$uriBuilder = $this->controllerContext->getUriBuilder();
95+
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
8396
$uriBuilder->reset()
84-
->setTargetPageUid($pageUid)
97+
->setTargetPageUid($this->arguments['pageUid'])
8598
->setUseCacheHash(true)
86-
->setSection($section)
87-
->setFormat($format)
88-
->setLinkAccessRestrictedPages($linkAccessRestrictedPages)
99+
->setSection($this->arguments['section'])
100+
->setFormat($this->arguments['format'])
101+
->setLinkAccessRestrictedPages($this->arguments['linkAccessRestrictedPages'])
89102
->setArguments($additionalParams)
90-
->setCreateAbsoluteUri($absolute)
91-
->setAddQueryString($addQueryString)
92-
->setAddQueryStringMethod($addQueryStringMethod)
93-
->setArgumentsToBeExcludedFromQueryString($argumentsToBeExcludedFromQueryString);
103+
->setCreateAbsoluteUri($this->arguments['absolute'])
104+
->setAddQueryString($this->arguments['addQueryString'])
105+
->setAddQueryStringMethod($this->arguments['addQueryStringMethod'])
106+
->setArgumentsToBeExcludedFromQueryString($this->arguments['argumentsToBeExcludedFromQueryString']);
94107

95-
return $uriBuilder->uriFor($action, $arguments, $controller, $extensionName, $pluginName);
108+
return $uriBuilder->uriFor($this->arguments['action'], $this->arguments['arguments'], $this->arguments['controller'], $extensionName, $pluginName);
96109
}
97110

98111
/**
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
return [
4+
'frontend' => [
5+
'helhum/typoscript-rendering-handler' => [
6+
'target' => Helhum\TyposcriptRendering\Middleware\TypoScriptRenderingHandler::class,
7+
'description' => '',
8+
'after' => [
9+
'typo3/cms-frontend/prepare-tsfe-rendering',
10+
],
11+
],
12+
],
13+
];

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"license": "GPL-2.0-or-later",
2323
"require": {
2424
"php": ">=7.0.0 <7.4",
25-
"typo3/cms-core": "^7.6 || ^8.7"
25+
"typo3/cms-core": "^7.6 || ^8.7 || ^9.5"
2626
},
2727
"require-dev": {
2828
"nimut/testing-framework": "^2.0 || ^3.0 || ^4.0"

0 commit comments

Comments
 (0)